Skip to content

Commit

Permalink
Bugfix for library update if model has been pickled
Browse files Browse the repository at this point in the history
  • Loading branch information
M1ha-Shvn committed Dec 5, 2019
1 parent c9511dc commit ed5a321
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='django-pg-returning',
version='1.2.2',
version='1.2.3',
packages=['django_pg_returning'],
package_dir={'': 'src'},
url='https://github.com/M1hacka/django-pg-returning',
Expand Down
8 changes: 6 additions & 2 deletions src/django_pg_returning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_updat
Try to update the model. Return True if the model was updated (if an
update query was done and a matching row was found in the DB).
"""
# If object has been saved in cache using pickle before library update
# It can cause getting attribute fail
is_returning_update = getattr(self, '_returning_update', False)

filtered = base_qs.filter(pk=pk_val)
if not values:
# We can end up here when saving a model in inheritance chain where
Expand All @@ -64,15 +68,15 @@ def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_updat
# successfully (a row is matched and updated). In order to
# distinguish these two cases, the object's existence in the
# database is again checked for if the UPDATE query returns 0.
if self._returning_update:
if is_returning_update:
updated_count = self._do_update_and_refresh(filtered, values, update_fields)
else:
updated_count = filtered._update(values)
return updated_count > 0 or filtered.exists()
else:
return False

if self._returning_update:
if is_returning_update:
return self._do_update_and_refresh(filtered, values, update_fields) > 0
else:
return filtered._update(values) > 0
Expand Down

0 comments on commit ed5a321

Please sign in to comment.