#14471: db.models.Manager regression - can't override some methods
---------------------------------------------------+------------------------
Reporter: Lucky | Owner: nobody
Status: new | Milestone: 1.3
Component: Database layer (models, ORM) | Version: 1.2
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by russellm):
* stage: Unreviewed => Accepted
* milestone: => 1.3
Old description:
> I want to migrate my project from the django-1.1.2 to the django 1.2.3
> and I have problem with custom model managers what overrides
> Manager.create() method. For example:
>
> {{{
> class Book(models.Model):
> title = models.CharField(max_length=10)
> author = models.ForeignKey(Author)
> objects = CustomManager()
>
> class CustomManager(models.Manager):
> def create(self, **kwargs):
> # business logic here
> return super(CustomManager, self).create(**kwargs)
> }}}
>
> Django 1.2.3 uses the CustomManager.create() method on the 'objects'
> descriptor as expected.
> {{{
> Book.objects.create(author=a1, title='How to be smart')
> }}}
>
> In the django-1.1.2 the same behavior had related field 'book_set'
> descriptor .
> But in the 1.2.3 CustomManager.create() does not called anymore on
> related field. The next code has different behavior:
>
> {{{
> author.book_set.create(title='How to program')
> }}}
>
> The difference in the implementation for `create` method in the
> RelatedManger class. In the 1.1.2 it was delegate result to the create()
> method of it superclass (CustomManager).
>
> {{{
> return super(RelatedManager, self).create(**kwargs)
> }}}
> http://code.djangoproject.com/browser/django/tags/releases/1.1.2/django/db/models/fields/related.py#L367
>
> But the 1.2. delegates result to the result of .using(db), what is not
> superclass, but QuerySet.
> {{{
> return super(RelatedManager, self).using(db).create(**kwargs)
> }}}
> http://code.djangoproect.com/browser/django/trunk/django/db/models/fields/related.py#L423
>
> Look for the actual test case in the attachement. I'm Sorry for my silly
> english.
New description:
I want to migrate my project from the django-1.1.2 to the django 1.2.3 and
I have problem with custom model managers what overrides Manager.create()
method. For example:
{{{
class Book(models.Model):
title = models.CharField(max_length=10)
author = models.ForeignKey(Author)
objects = CustomManager()
class CustomManager(models.Manager):
def create(self, **kwargs):
# business logic here
return super(CustomManager, self).create(**kwargs)
}}}
Django 1.2.3 uses the CustomManager.create() method on the 'objects'
descriptor as expected.
{{{
Book.objects.create(author=a1, title='How to be smart')
}}}
In the django-1.1.2 the same behavior had related field 'book_set'
descriptor .
But in the 1.2.3 CustomManager.create() does not called anymore on related
field. The next code has different behavior:
{{{
author.book_set.create(title='How to program')
}}}
The difference in the implementation for `create` method in the
RelatedManger class. In the 1.1.2 it was delegate result to the create()
method of it superclass (CustomManager).
{{{
return super(RelatedManager, self).create(**kwargs)
}}}
http://code.djangoproject.com/browser/django/tags/releases/1.1.2/django/db/models/fields/related.py#L367
But the 1.2. delegates result to the result of .using(db), what is not
superclass, but QuerySet.
{{{
return super(RelatedManager, self).using(db).create(**kwargs)
}}}
http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L423
Look for the actual test case in the attachement. I'm Sorry for my silly
english.
--
Ticket URL: <http://code.djangoproject.com/ticket/14471#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.