crate / sqlalchemy-cratedb

SQLAlchemy dialect for CrateDB.
https://cratedb.com/docs/sqlalchemy-cratedb/
Apache License 2.0
3 stars 2 forks source link

Sqlalchemy doesn't update nested elements in objects #130

Closed jpalanco closed 7 years ago

jpalanco commented 8 years ago

Using sqlalchemy is not possible to update a nested element.

Example

Model:

>>> from crate.client.sqlalchemy.types import Object, ObjectArray
>>> from uuid import uuid4

>>> class Character(Base):
...     __tablename__ = 'characters'
...     id = sa.Column(sa.String, primary_key=True, default=gen_key)
...     name = sa.Column(sa.String)
...     quote = sa.Column(sa.String)
...     details = sa.Column(Object)
...     more_details = sa.Column(ObjectArray)
...     name_ft = sa.Column(sa.String)
...     quote_ft = sa.Column(sa.String)

We try to update a Character:

>>> char = session.query(Character).filter_by(name='Arthur Dent').one()
>>> char.details['gender'] = 'manly man'
>>> char.details['field_A']['sub_field_a'] = 'value_aaaa'
>>> session.commit()
>>> session.refresh(char)

SQLAlchemy generates the following query:

UPDATE characters SET details['gender'] = 'manly man' WHERE analysis.id = '955ce9c7-e85f-489d-b48c-bf6e216c10fe';

But char.details['field_A']['sub_field_a'] is not taken in account in the query. The expected query is:

UPDATE characters SET details['gender'] = 'manly man', details['field_A']['sub_field_a'] = 'value_aaaa' WHERE analysis.id = '955ce9c7-e85f-489d-b48c-bf6e216c10fe';

Versions:

Python 2.7 Crate Data Python client 0.16.3 SQLalchemy 0.9.9

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

chaudum commented 8 years ago

thanks for reporting. we'll have a look!

memcmp commented 8 years ago

Hi @jpalanco,

thanks for reporting the issue. i have fixed it with https://github.com/crate/crate-python/commit/c0bfac6af2d2eeb08367e75aa1309d554c6241bb

The fix will be part of the next release :)

mikethebeer commented 7 years ago

will close this, since 0.16.5 is released.