Issue in custom init while using get
See original GitHub issueSince 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:
- Created 8 years ago
- Comments:11 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
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:
On the exception I’ll have to investigate further.
id is also now used by neomodel v3 so i’d avoid using it as a property name