-
Notifications
You must be signed in to change notification settings - Fork 286
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
dictionary-named methods are raising a validation exception #489
Conversation
Indeed this will fix this test case, but users that override other mapping methods (ex: "keys") will still break (relevant: #375). Also, overriding "get" will break other things (ex: convert(m._schema, m) == convert(m._schema, m._data) I could go ahead and merge this, but not sure a new release is warranted until a more general fix is achieved. |
@lkraider thanks, that ticket provided a lot of context. I see why this doesn't solve the larger collisions that occur between field names and the reserved method names of the Mapping type itself. It sounds like there's a lot of work to get to the point of separating the two apart (and a significant part backwards-incompatible). I can avoid dealing with this head on by using serialize_name and deserialize_from for now. I would still argue this patch should be considered. It's a minimal change that allows better compatibility with the set, at least as far as the core schematics serialize logic is concerned. I actually think embarking on the larger solution is a good long-term goal, but I personally don't have the bandwidth to tackle that right now. I've made a change to rely on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 from me after these few changes
@@ -1,4 +1,3 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change whitespace formatting in this patch.
tests/test_models.py
Outdated
@@ -658,4 +684,3 @@ class M(Model): | |||
m = ListType(ModelType('M', required=True), required=True) | |||
|
|||
M.get_mock_object() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See first comment.
|
||
m = M({"items": 1, "values": 1, "get": 1}) | ||
m.validate() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for nested ModelType that override mapping methods too:
def test_nested_model_override_mapping_methods():
class Nested(Model):
items, values, get, keys = IntType(), IntType(), IntType(), IntType()
class Root(Model):
keys = ModelType(Nested)
root = Root({"keys": {"items": 1, "values": 1, "get": 1, "keys": 1}})
root.validate()
assert root.keys.items == 1
I put forward a patch on master that fixes the reliance on |
f76a0d7
to
8a3bf44
Compare
8a3bf44
to
cd94171
Compare
Sounds good! Addressed all feedback, I believe. Thanks for fixing up the keys behavior as well! Also just rebased on top of your changes, hope that's ok. not sure how that affects the existing CR. |
Let me know if you have issues with the latest master. I will prepare a 2.0.1 release including this fixes later in the week. |
FYI: v2.0.1 was just released to PyPI and contains these fixes. |
works for me, thanks! |
There's currently a bug where naming fields of a model after the dictionary methods will raise an incorrect DataError during validation (see unit test or toumorokoshi/transmute-core#20)
Looking at the documentation, the atoms() method shouldn't support anything besides a mapping anyway. This builds off of that assumption, and removes the getattr call.