#27128: A method model.objects.get(pk=obj.pk) returns many objects, but in a
database is one.
-------------------------------------+-------------------------------------
Reporter: setivolkylany | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution:
Keywords: GenericRelation, | Triage Stage:
Testing, Models | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by setivolkylany):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Very strange behaviour of the Django ORM while testing (now I am using
> pytest)
>
> I have two apps "books" and "replies".
> The app "books" has two models http://pastebin.com/gDMi7UpU
> The app "replies" has one model http://pastebin.com/u9FabQQA
>
> For create new objects I am using factories for replies -
> http://pastebin.com/pGtiwS2m, for books and writers -
> http://pastebin.com/NQ6AWxib
>
> While testing methods of queryset of the model Book I got error, where it
> should not be
>
> A file querysets.py of the app "books" http://pastebin.com/FVnLLzxK
> Tests for the file querysets.py of the app "books"
> http://pastebin.com/rmpDm0Ae
>
> For testing I am using the pytest with next configuration in a file
> pytest.ini
>
> {{{
> [pytest]
> addopts = -s --reuse-db --ff --maxfail=1
> apps/books/tests/test_querysets.py::Tests
> DJANGO_SETTINGS_MODULE=config.settings.development
> }}}
>
> Run test as next py.test
>
> Traceback http://pastebin.com/Vv96XLzm
>
> After many time googling and dipping in the Django`s code by the
> traceback I decided it is bug in the Django
>
> I think it is the problem related with that models the Book and the Reply
> is related by help the field GenericRelation, but I don`t found facts for
> it.
>
> Sorry for my grammar mistakes, I was no originally an English
>
> If need another codes from my project, please tell about it
New description:
Very strange behaviour of the Django ORM while testing (now I am using
pytest)
I have two apps "books" and "replies".
The app "books" has two models http://pastebin.com/gDMi7UpU
The app "replies" has one model http://pastebin.com/u9FabQQA
For create new objects I am using factories for replies -
http://pastebin.com/pGtiwS2m, for books and writers -
http://pastebin.com/NQ6AWxib
While testing methods of queryset of the model Book I got error, where it
should not be
A file querysets.py of the app "books" http://pastebin.com/FVnLLzxK
Tests for the file querysets.py of the app "books"
http://pastebin.com/rmpDm0Ae
For testing I am using the pytest with next configuration in a file
pytest.ini
{{{
[pytest]
addopts = -s --reuse-db --ff --maxfail=1
apps/books/tests/test_querysets.py::Tests
DJANGO_SETTINGS_MODULE=config.settings.development
}}}
Run test as next py.test
Traceback http://pastebin.com/Vv96XLzm
After many time googling and dipping in the Django`s code by the traceback
I decided it is bug in the Django
I think it is the problem related with that models the Book and the Reply
is related by help the field GenericRelation, but I don`t found facts for
it.
Sorry for my grammar mistakes, I was no originally an English
If need another codes from my project, please tell about it
Update
Same error I had when tested a method "get_admin_url()" of the model Book
with next a testing code
{{{
def test_get_admin_url(self):
self.client.force_login(self.active_superuser)
response = self.client.get(self.book.get_admin_url())
self.assertEqual(response.status_code, 200)
}}}
Ending a traceback
{{{
if not num:
raise self.model.DoesNotExist(
"%s matching query does not exist." %
self.model._meta.object_name
)
raise self.model.MultipleObjectsReturned(
"get() returned more than one %s -- it returned %s!" %
> (self.model._meta.object_name, num)
)
E apps.books.models.MultipleObjectsReturned: get() returned more
than one Book -- it returned 3!
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27128#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.2d1b342fe93cca2566ec40beaffc6403%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.