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

Fixes SlugField with no_dereference #2048

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Use "udata" and fix a few other typos in documentation and UI/translation strings [#2023](https://github.com/opendatateam/udata/pull/2023)
- Add a surrounding block declaration around community section [2039](https://github.com/opendatateam/udata/pull/2039)
- Fix broken form validation on admin discussions and issues [#2045](https://github.com/opendatateam/udata/pull/2045)
- Fix full reindexation by avoiding `SlugField.instance` deepcopy in `no_dereference()` querysets [#2048](https://github.com/opendatateam/udata/pull/2048)

## 1.6.4 (2019-02-02)

Expand Down
7 changes: 7 additions & 0 deletions udata/models/slug_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, populate_from=None, update=False, lower_case=True,
self.lower_case = lower_case
self.separator = separator
self.follow = follow
self.instance = None
super(SlugField, self).__init__(**kwargs)
if follow:
# Can't use sender=self.owner_document which is not yet defined
Expand All @@ -43,6 +44,12 @@ def __set__(self, instance, value):
self.instance = instance
return super(SlugField, self).__set__(instance, value)

def __deepcopy__(self, memo):
# Fixes no_dereference by avoiding deep copying instance attribute
copied = self.__class__()
copied.__dict__.update(self.__dict__)
return copied

def validate(self, value):
populate_slug(self.instance, self)

Expand Down