pyeve / eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
http://eve-sqlalchemy.readthedocs.io
Other
234 stars 70 forks source link

In PUT method on element in collection error in creation of new object causes record to be deleted #64

Closed mmiz closed 9 years ago

mmiz commented 9 years ago

Seems like a bug. I'm using version 0.3.4, eve 0.5.3, using schema from tutorial http://eve-sqlalchemy.readthedocs.org/en/stable/tutorial.html ID_FIELD field is set to "id": ID_FIELD = 'id' ITEM_LOOKUP_FIELD = ID_FIELD config.ID_FIELD = ID_FIELD config.ITEM_LOOKUP_FIELD = ID_FIELD

schema:

DOMAIN = { 'people': People._eve_schema['people'], 'invoices': Invoices._eve_schema['invoices'] }

DOMAIN['people'].update({ 'item_title': 'person', 'additional_lookup': { 'url': '[0-9]+', 'field': 'id' }, 'cache_control': 'max-age=10,must-revalidate', 'cache_expires': 10, 'resource_methods': ['GET', 'POST', 'DELETE'], 'item_methods': ['GET', 'PATCH', 'PUT', 'DELETE'] })

Steps to reproduce: 1) POST /people {"lastname": "Jonh", "Doe"} Response id: 1 2) PUT /people/1
{"lastname": "Jonh", "Doe"} Response: 400 "Can's set attribute".

I looked into the debugger, exception is raised on line 231 in init.py:

model_instance._id = id_

It seems like id field name is used incorrectly. I'm new to eve and eve-sqlalchemy, so I'm not sure how to fix it properly (e.g. where is the name of the field is stored)

AND EVEN MORE IMPORTANTLY: This bug causes incorrect behavior. Put request failed, and I expect that nothing changes. But the record is deleted from the database, because it is done in separate transaction! And any error in model creation would lead to this behavior

PATCH works as expected though.

mmiz commented 9 years ago

Figured out that the bug with "id" was caused by @hybrid_property _id in CommonColumns from here: https://github.com/RedTurtle/eve-sqlalchemy/blob/master/examples/tables.py

But the bug with record deletion remains. Why is the operation performed in 2 transactions??

goneri commented 9 years ago

closed by commit 7fab83ba2e46540d19f9a0a05dbacaa656776bcf.