Fixes SlugField with no_dereference #2048
Merged
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.
This one was tricky !!!
This PR fixes the
udata search index
command and more specificaly the.no_dereference()
usage withSlugField
.Root cause
In MongoEngine 0.16,
no_reference()
behavior change to usecopy.deepcopy
on fields (sadly Mongoengine make extensive use ofcopy.deepcopy
which is bad for performances).On the other side, the
SlugField
need to keep a reference to its owning instance to be able to properly slugify on save.As a consequence,
copy.deepcopy
was trying to copy theSlugField.instance
field which is a model and cannot be deepcopied easilyFix
copy.deepcopy
allows to override the deepcopy behavior by implementing a__deepcopy__(self, memo)
method. This is done in this PR by making a proper newSlugField
instanceFuture thought
The extensive use of
copy.deepcopy
might have a bad impact on performance. In order to improve that, we might need to implement some custom__deepcopy__(self, memo)
methods on other objects because this is not done by MongoEngine itself.As
flask-restplus
also make use ofcopy.deepcopy
, implementing custom__deepcopy__(self, memo)
methods on models might improve performance both on DB and API sides.