question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue in custom init while using get

See original GitHub issue

Since neomodel does not have any auto incrementing id, I decided to create an IntegerField called id and set its value to current count of that node class + 1. For this I overwrote the init class as in given example:

class NodeClass:
     id = neomodel.IntegerProperty()
     # more fields ...
     def __init__(self,*args,**kwargs):
          if id not in kwargs: 
              kwargs["id"] = len(NodeClass.nodes) + 1
          super(NodeClass,self).__init__(self,*args,**kwargs)

When I create a new instance of this NodeClass, everything is fine ( id is also set correctly). But when I try to use the get method as

NodeClass.nodes.get(id=123)

I get the following exception:

super(type, obj): obj must be an instance or subtype of type

P.S provided the code sample so just to make sure that I am not doing anything wrong instead of neomodel

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bleib1djcommented, Jun 8, 2015

@siddharthm just as a note I’d recommend utilizing something like python’s UUID package to generate unique identifiers for nodes, it’s a bit more scalable and doesn’t run the risk of race conditions under load which this implementation may run into if a node hasn’t been written to the database yet and the init method gets called. This will also cause a lot less querying to occur. To create your id you would do something along the lines of

from uuid import uuid1

id = uuid1()

On another note if you do it this way you don’t have to override init and can just set the function as the default parameter so it would look something like:

class NodeClass:
     id = neomodel.StringProperty(default=uuid1, unique_index=True)

On the exception I’ll have to investigate further.

0reactions
robinedwardscommented, Nov 24, 2016

id is also now used by neomodel v3 so i’d avoid using it as a property name

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I write a custom init for a UIView subclass in Swift?
The init(frame:) version is the default initializer. You must call it only after initializing your instance variables. If this view is being reconstituted ......
Read more >
Custom init() is not recognized anymore · Issue #247 - GitHub
There is a problem when using custom init() code on a ParseObject class. I get the error Type 'User' does not conform to...
Read more >
Fixing "Class ViewController has no initializers" - free Swift 5.4 ...
There are two ways to solve this problem: either provide a default value for your property when you define the property, or create...
Read more >
Handling view controllers that have custom initializers
One way that can be used if the dependencies that we're looking to inject can be retrieved statically (such as when using the...
Read more >
Init only setters - C# 9.0 draft specifications - Microsoft Learn
This feature specification describes the rules for 'init' only setters in properties. These can be set only as part of an instantiation, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found