scholrly / neo4django

Drop-in Neo4j/Django integration.
GNU General Public License v3.0
358 stars 83 forks source link

make error message more understandable / raise helpful error #157

Open szabi opened 11 years ago

szabi commented 11 years ago

I came across this unhelpful error message.

>>> e=Evidence(id=1,name='E1',as_of=datetime(2013,05,27,21,44))
>>> e.families.add(f)
>>> e.persons.add(h,w,c,b)
>>> e.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/[...]/neo4django/db/models/base.py", line 325, in save
    return super(NodeModel, self).save(using=using, **kwargs)
  File "/[...]/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/[...]/neo4django/db/models/base.py", line 342, in save_base
    self._save_properties(self, self.__node, is_new)
  File "/[...]/neo4django/db/models/properties.py", line 394, in _save_
    propMap=gremlin_props, raw=True)
  File "/[...]/neo4django/neo4jclient.py", line 178, in gremlin_tx
    return self.gremlin(script, tx=True, **params)
  File "/[...]/neo4django/neo4jclient.py", line 167, in gremlin
    params)
  File "/[...]/neo4django/neo4jclient.py", line 152, in send_script
    script_rv = ext.execute_script(s, params=params, **execute_kwargs)
  File "/[...]/neo4jrestclient/client.py", line 2089, in __call__
    raise StatusException(response.status, msg)
StatusException: Error [400]: Bad Request. Bad request syntax or unsupported method.
Invalid data sent: javax.script.ScriptException: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: id for class: com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jVertex

It turned out the model did not like me using id as a property. Then I remembered, that either in django or neo4django I read that reserved words would be not allowed, maybe that was my fault, however, I think the error message raised is not very helpful. Maybe catch the error earlier and raise a helpful exception?

mhluongo commented 11 years ago

Yep, in neo4django 'id' always refers to the id of the node behind the model instance. I'll look into catching id declarations and raising a sensible error on model definition, insteady of that mess. Honestly, even the above should be raise a reasonable exception type (maybe something like 'GremlinException').

By the way, if you do need a custom id you can still declare any other field as an AutoProperty. On May 27, 2013 4:08 PM, "szabi" notifications@github.com wrote:

I came across this unhelpful error message.

e=Evidence(id=1,name='E1',as_of=datetime(2013,05,27,21,44))>>> e.families.add(f)>>> e.persons.add(h,w,c,b)>>> e.save()Traceback (most recent call last): File "", line 1, in File "/[...]/neo4django/db/models/base.py", line 325, in save return super(NodeModel, self).save(using=using, _kwargs) File "/[...]/django/db/models/base.py", line 463, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "/[...]/neo4django/db/models/base.py", line 342, in save_base self._save_properties(self, self.__node, is_new) File "/[...]/neo4django/db/models/properties.py", line 394, in save propMap=gremlin_props, raw=True) File "/[...]/neo4django/neo4jclient.py", line 178, in gremlin_tx return self.gremlin(script, tx=True, _params) File "/[...]/neo4django/neo4jclient.py", line 167, in gremlin params) File "/[...]/neo4django/neo4jclient.py", line 152, in send_script script_rv = ext.execute_script(s, params=params, execute_kwargs) File "/[...]/neo4jrestclient/client.py", line 2089, in call** raise StatusException(response.status, msg)StatusException: Error [400]: Bad Request. Bad request syntax or unsupported method.Invalid data sent: javax.script.ScriptException: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: id for class: com.tinkerpop.blueprints.pgm.impls.neo4j.Neo4jVertex

It turned out the model did not like me using id as a property. Then I remembered, that either in django or neo4django I read that reserved words would be not allowed, maybe that was my fault, however, I think the error message raised is not very helpful. Maybe catch the error earlier and raise a helpful exception?

— Reply to this email directly or view it on GitHubhttps://github.com/scholrly/neo4django/issues/157 .