-
Notifications
You must be signed in to change notification settings - Fork 71
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
Django 1.10 error on add new instance #49
Comments
Confirm, same here |
Have the same. I have spend some time to debug the problem, and I know what causes the issue, but cannot figure out how to fix it. So I will share what I discovered. Everything breaks because of the change in implementation of It used to be like that (Django 1.9): def get_deferred_fields(self):
"""
Returns a set containing names of deferred fields for this instance.
"""
return {
f.attname for f in self._meta.concrete_fields
if isinstance(self.__class__.__dict__.get(f.attname), DeferredAttribute)
} But now it is (Django 1.10): def get_deferred_fields(self):
"""
Returns a set containing names of deferred fields for this instance.
"""
return {
f.attname for f in self._meta.concrete_fields
if f.attname not in self.__dict__
} The problem is that Going a little bit deeper brought me to def contribute_to_class(self, cls, name):
super(PositionField, self).contribute_to_class(cls, name)
for constraint in cls._meta.unique_together:
if self.name in constraint:
raise TypeError("%s can't be part of a unique constraint." % self.__class__.__name__)
self.auto_now_fields = []
for field in cls._meta.fields:
if getattr(field, 'auto_now', False):
self.auto_now_fields.append(field)
setattr(cls, self.name, self)
pre_delete.connect(self.prepare_delete, sender=cls)
post_delete.connect(self.update_on_delete, sender=cls)
post_save.connect(self.update_on_save, sender=cls) That line causes the position attribute to be missing from position = PositionField() The Few last things I came along:
Source, look for "Class instances" section. A workaround for that can be very simple, just override the def get_deferred_fields(self):
deferred_set = super().get_deferred_fields()
return {f for f in deferred_set if f != 'position'} Assuming the position attribute in model class is called |
New deferred logic indeed looks strange. Added workaround for that. Tested locally. |
It doesn't work in Django 1.10. Might add it back if jpwatts/django-positions#49 is fixed. The package dependency can't be removed because it's required for migrations. Closes #296
Hi, I had a similar error just by overriding save method and overriding get_deferred_fields worked as a workaround. So thanks! Have you considered reporting that to Django? |
I faced the same issue and also for me overriding get_deferred_fields worked! Thanks a lot @akszydelko :) |
Thank you @akszydelko this helped us immensely |
I have model with PositionField. On create instance i got error:
The text was updated successfully, but these errors were encountered: