-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
4.10.0 breaks libraries that subclass validator classes #982
Comments
At first glance that code seems to be subclassing validators, which isn't something that's really supported, so I guess I'm not surprised it unfortunately changed behavior. It may be that it's possible to fix easily though (both here and there). I'd have to see why they're doing what's there to really know what they should be doing instead, and really they should use a supported way of extending validator behavior (and really I should have long ago explicitly made subclassing warn and then raise an error rather than just saying it in various issues here :/, so that's my mistake.) |
evolve
breaks openapi-schema-validator
The commit I just pushed (and release which should go out in a few minutes) should fix this I believe -- though as I mentioned:
I didn't take the longest look at asdf or what the OpenAPI repo was doing but I think both should be relatively easy to do without inheritance. If more help's needed, yeah, feel free to follow up! |
I can confirm that the commit fixes the majority of the issues related to the The issue of missing attributes still persists, but I suppose they can fix that with composition instead of inheritance, or however else they plan to adjust their validators. |
Thanks! Hm, I don't think there's anything else different happening now relative to what |
I think this is a simplified bit of code that does what they do from attr import attrib
from attr import attrs
from jsonschema.validators import create
BaseValidator = create(meta_schema={})
@attrs
class Validator(BaseValidator):
read: bool = attrib(default=None)
write: bool = attrib(default=None)
def bug(self):
return self.evolve()
validator = Validator(write=True, schema={})
evolved = validator.bug()
print(validator.write)
print(evolved.write)
assert validator.write == evolved.write |
It could be as simple as changing the field iterator to for field in attr.fields(self.__class__): But I'm not sure of all the implications. Haven't really looked much into what the code truly does and needs for either of the projects. |
Here for renamed attributes out of attrs-using classes. Refs: '#982 (comment)'
Ah, indeed. OK, the second place is fixed too in the commit I just pushed, thanks. |
Unfortunately, even with the latest changes (a8c3b14), ASDF is still broken by
as the last item in the traceback. Still with the emitted warning:
I am happy to discuss this in a separate issue and/or discuss how to migrate ASDF away from using the unintended API. I |
@WilliamJamieson aw. I'll reopen the other issue you opened and we can diagnose (both how to fix now and then yeah later too) |
Doing so was not intended to be public API, though it seems some downstream libraries do so. A future version will make this an error, as it is brittle and better served by composing validator objects instead. Feel free to reach out if there are any cases where changing existing code seems difficult and I can try to provide guidance. Refs: #982
The failing code is here:
https://github.com/p1c2u/openapi-schema-validator/blob/4d8fd4c2bddce50931ea617bca54d526ae0535cd/openapi_schema_validator/validators.py#L78-L96
It does look very strange that the new
evolve
method doesn't keep the attributes of the OAS30Validator class.There they have an
@attrs
class. It defines aread
andwrite
attribute. And after evolving, not only are theread
andwrite
attributes gone, but super calls as line 96 don't work either.I have also made an issue in their project: python-openapi/openapi-schema-validator#46
I am not sure which one of the projects should update. But I feel that this new
evolve
method only does half of what it used to do and is not good enough to replace anattrs.evolve
jsonschema/jsonschema/validators.py
Lines 204 to 216 in ae0feea
The text was updated successfully, but these errors were encountered: