I'm porting one of my applications to 1.0, and have come across what
seems like a bug related to the Queryset refactor. Previously, it was
possible to have a model's default manager filter the results; something
like:
class ActiveManager(models.Manager):
def get_query_set(self):
qs = super(ActiveManager, self).get_query_set()
return qs.filter(is_active=True)
class InactiveManager(models.Manager):
[...]
class Item(models.Model):
is_active = models.BooleanField()
objects = ActiveManager()
inactive_objects = InactiveManager()
It no longer seems possible to do so. Pre-QSRF, Model.save used raw SQL
to determine whether a given row existed (and thus whether to update or
insert). Now Model.save_base uses the class's default manager, so
attempting to save an existing, inactive Item in my example above
results in a duplicate key violation. Passing force_update=True is no
help, as Model.save_base uses cls._default_manager.filter to perform the
update.
Am I missing something, or is this simply unsupported now? The
documentation notes that it's "a good idea to be careful in your choice
of default manager," but doesn't clearly state that a model's default
manager must not filter its objects.
-Zak
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---