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

AttributeError: 'super' object has no attribute 'coerce' when setting value as None #10

Closed
idavidmcdonald opened this issue Mar 13, 2018 · 7 comments

Comments

@idavidmcdonald
Copy link
Contributor

If I have a JSON field, say a_json that has been associated with NestedMutable I cannot set it's value as None without triggering an AttributeError as None does not have the coerce attribute.

For example:

File "example.py", line 83, in <module>
    item1.a_json = None
  File "/Users/davidmcdonald/sqlalchemy-bug-example/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 229, in __set__
    instance_dict(instance), value, None)
  File "/Users/davidmcdonald/sqlalchemy-bug-example/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 708, in set
    value, old, initiator)
  File "/Users/davidmcdonald/sqlalchemy-bug-example/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 715, in fire_replace_event
    state, value, previous, initiator or self._replace_token)
  File "/Users/davidmcdonald/sqlalchemy-bug-example/venv/lib/python3.6/site-packages/sqlalchemy/ext/mutable.py", line 495, in set
    value = cls.coerce(key, value)
  File "/Users/davidmcdonald/sqlalchemy-bug-example/venv/lib/python3.6/site-packages/sqlalchemy_json/__init__.py", line 44, in coerce
    return super(cls).coerce(key, value)

I believe setting the value as None should be allowed and should be quite an easy one to fix. I'm happy to put in a PR if you agree this is sensible, just let me know.

Thanks :)

@edelooff
Copy link
Owner

Yeah this seems like a bug. Nulling a field should certainly be possible.

Adding a check for None as a value in NestedMutable.coerce seems like a decent solution, and follows the base pattern laid out in SQLAlchemy's Mutable base type. A PR would be more than welcome.

@idavidmcdonald
Copy link
Contributor Author

idavidmcdonald commented Mar 13, 2018

Great, I'll put in a PR.

Would you like me to take care of a patch version bump or is this something you'd like to do separately?

@idavidmcdonald
Copy link
Contributor Author

Very simple PR up - #11. Feel free to take a look and I'll be happy to add any further changes.

@edelooff
Copy link
Owner

Thanks again.

I'll take care of the change log entry, version bump and new PyPI release when I have a bit of spare time.

@benvand
Copy link

benvand commented Oct 10, 2018

@edelooff Would love to see a pypi release for this. Let me know if I can do anything to help.

@edelooff
Copy link
Owner

@benvand https://pypi.org/project/sqlalchemy-json/ done, thanks for the request.

@casualuser
Copy link
Contributor

casualuser commented Oct 21, 2022

@edelooff it looks like this is still actual with https://pypi.org/project/sqlalchemy-json/0.5.0

casualuser added a commit to casualuser/sqlalchemy-json that referenced this issue Nov 18, 2022
repeat fix edelooff#10 for  NestedMutableDict and NestedMutableList
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

Successfully merging a pull request may close this issue.

4 participants