Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observer does not work with JSON columns #398

Open
miracle2k opened this issue Sep 21, 2019 · 0 comments
Open

Observer does not work with JSON columns #398

miracle2k opened this issue Sep 21, 2019 · 0 comments

Comments

@miracle2k
Copy link

If I observe a JSON column:

base = Column(UnicodeText)
data = Column(JSONB)

@observes('base', 'data')
def translite_observer(self, base, data):
    print(data)

And data is {"a": 1, "b": 2}, and I change the base attribute, then the observer will print:

set('a', 'b')

This is because two is_sequence checks:

  1. https://github.com/kvesteri/sqlalchemy-utils/blob/master/sqlalchemy_utils/functions/orm.py#L811
  2. https://github.com/kvesteri/sqlalchemy-utils/blob/master/sqlalchemy_utils/observer.py#L308

In both cases, the dict is treated as a sequence, is iterated over and converted into a list or set.

Note that the JSON column could also contain a list , so I think just ignoring dicts is not the right answer. Rather, there would need to be some knowledge about whether the value gotten from the model is from a relationship, or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant