[Django] #24079: Duplicate results of `ManyToManyField` when using 'though'

31 views
Skip to first unread message

Django

unread,
Jan 5, 2015, 5:09:57 AM1/5/15
to django-...@googlegroups.com
#24079: Duplicate results of `ManyToManyField` when using 'though'
----------------------------------------------+--------------------
Reporter: tanzaho | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
When using a many 2 many relation ship with 'though' parameter, the DB is
returning duplicates when several relations exists for the same pair of
objects.

I have the following relations :

{{{
tag 1
user 1 -----> article 1
tag 2
user 1 -----> article 1
}}}

'''Expected behavior :'''


{{{
user = User.objects.get(pk=1)
print user.article.all()
[<Article: 1>]
}}}


'''Observed behavior'''


{{{
user = User.objects.get(pk=1)
print user.article.all()
[<Article: 1>, <Article: 1>]
}}}

More details on Stack Overflow :
http://stackoverflow.com/questions/27777065/duplicate-results-of-
manytomanyfield-when-using-though

--
Ticket URL: <https://code.djangoproject.com/ticket/24079>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 5, 2015, 5:18:53 AM1/5/15
to django-...@googlegroups.com
#24079: Duplicate results of `ManyToManyField` when using 'though'
-------------------------------------+-------------------------------------
Reporter: tanzaho | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tanzaho):

* status: new => closed
* needs_better_patch: => 0
* resolution: => fixed
* needs_tests: => 0
* needs_docs: => 0


Comment:

Solved (http://stackoverflow.com/a/27777286/2550237)
One should use distinct() to remove duplicate entries.

I think a comment in the doc should be appropriated in the many 2 many
section.

--
Ticket URL: <https://code.djangoproject.com/ticket/24079#comment:1>

Django

unread,
Jan 5, 2015, 5:52:33 AM1/5/15
to django-...@googlegroups.com
#24079: Duplicate results of `ManyToManyField` when using 'through'
-------------------------------------+-------------------------------------
Reporter: tanzaho | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by tanzaho:

Old description:

> When using a many 2 many relation ship with 'though' parameter, the DB is
> returning duplicates when several relations exists for the same pair of
> objects.
>
> I have the following relations :
>
> {{{
> tag 1
> user 1 -----> article 1
> tag 2
> user 1 -----> article 1
> }}}
>
> '''Expected behavior :'''
>

> {{{
> user = User.objects.get(pk=1)
> print user.article.all()
> [<Article: 1>]
> }}}
>

> '''Observed behavior'''
>

> {{{
> user = User.objects.get(pk=1)
> print user.article.all()
> [<Article: 1>, <Article: 1>]
> }}}
>
> More details on Stack Overflow :
> http://stackoverflow.com/questions/27777065/duplicate-results-of-
> manytomanyfield-when-using-though

New description:

When using a many 2 many relation ship with 'through' parameter, the DB is


returning duplicates when several relations exists for the same pair of
objects.

I have the following relations :

{{{
tag 1
user 1 -----> article 1
tag 2
user 1 -----> article 1
}}}

'''Expected behavior :'''


{{{
user = User.objects.get(pk=1)
print user.article.all()
[<Article: 1>]
}}}


'''Observed behavior'''


{{{
user = User.objects.get(pk=1)
print user.article.all()
[<Article: 1>, <Article: 1>]
}}}

More details on Stack Overflow :
http://stackoverflow.com/questions/27777065/duplicate-results-of-
manytomanyfield-when-using-though

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24079#comment:2>

Reply all
Reply to author
Forward
0 new messages