Feature: Don't revalidate arrays on every change by default#149
Merged
Feature: Don't revalidate arrays on every change by default#149
Conversation
+ Switch to using a descriptor class instead of 'property' to be able to mock it out + Pass 'strict' through to the arraywrappers
houndci-bot
reviewed
Sep 10, 2018
| foo.a.append("bar") | ||
| assert validate_items.call_count == 3 | ||
|
|
||
| # We expect accessing data elements to not revalidate because strict would have revalidated on load |
There was a problem hiding this comment.
line too long (103 > 99 characters)
| validate_items = mocker.patch.object( | ||
| validator, "validate_items", side_effect=validator.validate_items | ||
| ) | ||
| validate = mocker.patch.object( |
There was a problem hiding this comment.
local variable 'validate' is assigned to but never used
| validate_items = mocker.patch.object( | ||
| validator, "validate_items", side_effect=validator.validate_items | ||
| ) | ||
| validate = mocker.patch.object( |
There was a problem hiding this comment.
local variable 'validate' is assigned to but never used
| @@ -0,0 +1,82 @@ | |||
| import python_jsonschema_objects as pjs | |||
| import python_jsonschema_objects.wrapper_types | |||
There was a problem hiding this comment.
'python_jsonschema_objects.wrapper_types' imported but unused
| addl_constraints is expected to be key-value pairs of any of the other | ||
| constraints permitted by JSON Schema v4. | ||
| """ | ||
| logger.debug(fmt("Constructing ArrayValidator with {} and {}", item_constraint, addl_constraints)) |
There was a problem hiding this comment.
line too long (106 > 99 characters)
| 'validator': python_jsonschema_objects.wrapper_types.ArrayWrapper.create(uri, | ||
| item_constraint=typ, | ||
| addl_constraints=detail)} | ||
| 'validator': python_jsonschema_objects.wrapper_types.ArrayWrapper.create( |
There was a problem hiding this comment.
line too long (113 > 99 characters)
| propdata = {'type': 'array', | ||
| 'validator': python_jsonschema_objects.wrapper_types.ArrayWrapper.create(uri, item_constraint=typ, | ||
| addl_constraints=detail)} | ||
| 'validator': python_jsonschema_objects.wrapper_types.ArrayWrapper.create( |
There was a problem hiding this comment.
line too long (113 > 99 characters)
EliahKagan
added a commit
to EliahKagan/python-jsonschema-objects
that referenced
this pull request
Aug 20, 2023
The preceding commit (f0747ce) shows that mocking and counting calls to validator.validate verifies the same number of calls to it as to validator.validate_items (which already had assertions). However, that validator.validate is called this number of times, and no more, in the non-strict test, does not appear to be a fact that the tests in test_regression_143 intend to claim and verify. There are multiple places where a strictness check can prevent validate_items from being called. One is in the typed_elems property getter, which conditionally calls validate, which calls validate_items, and that's what happens in this test. But validate calls validate_items conditionally as well. A refactoring of the code could potentially cause more validate calls to happen in the non-strict case while still not increasing the call count for validate_items. Furthermore, the specific goal of this test is to verify that the change in cwacek#149 (for cwacek#143) is and remains effective, and the key goal there is to avoid unnecessarily revalidating *arrays*, so validate_items is the specifically relevant function to instrument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #143 by checking dirty flags for arrays and properties before revalidating. In order to allow for strict mode, this also passes the 'strict' flag down to the Array validator, in which case it will revalidate on every change.