[Django] #24352: Coercing ManyRelatedManager to string raises StopIteration exception

20 views
Skip to first unread message

Django

unread,
Feb 16, 2015, 12:53:43 PM2/16/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
----------------------------------------------+--------------------
Reporter: rasca | 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
----------------------------------------------+--------------------
As with #22982 this is broken in 1.7.

It should be trivial to workaround adding

{{{
def __str__(self):
return repr(self)
}}}

as in 29585e9b6a0ce15dc0149c8424cd11c3e27ee295 but this may be present in
some other parts of django or custom managers, so maybe it would be a good
idea to try a better fix.

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

Django

unread,
Feb 16, 2015, 1:24:40 PM2/16/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------

Reporter: rasca | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* easy: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Feb 16, 2015, 8:45:10 PM2/16/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned

Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by gmunumel):

* owner: nobody => gmunumel
* status: new => assigned


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

Django

unread,
Feb 22, 2015, 8:19:45 PM2/22/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

Here is the PR: https://github.com/django/django/pull/4191

I got an error with the isort test. I don't know if it is related to my
change.

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:3>

Django

unread,
Feb 22, 2015, 8:54:38 PM2/22/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by charettes):

You should base your patch against the master branch. It will be
backported by the committer.

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:4>

Django

unread,
Feb 23, 2015, 5:41:41 AM2/23/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

Replying to [comment:4 charettes]:


> You should base your patch against the master branch. It will be
backported by the committer.

But is this apply for any change? For instance, if I have a change for 1.4
branch I need to go against master branch?

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:5>

Django

unread,
Feb 23, 2015, 6:36:30 AM2/23/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

I saw this documentation:
https://docs.djangoproject.com/en/1.7/internals/contributing/committing-
code/#committing-guidelines . If I want to backport my PR I need to change
its title? The revision hash code is the code of the commit?

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:6>

Django

unread,
Feb 23, 2015, 1:05:20 PM2/23/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by charettes):

> For instance, if I have a change for 1.4 branch I need to go against
master branch?

Yes, but per our [https://docs.djangoproject.com/en/1.7/internals/release-
process/#backwards-compatibility-policy backport policy] the
`stable/1.4.x` would only receive security fixes and bug fixes for data
loss issues.

> I saw this documentation:
https://docs.djangoproject.com/en/1.7/internals/contributing/committing-
code/#committing-guidelines . If I want to backport my PR I need to change
its title? The revision hash code is the code of the commit?

The commit message will be changed by the committer through an automated
script.

You just have a to open a new pull request against master with your
changes and a commit message following
[https://docs.djangoproject.com/en/1.7/internals/contributing/committing-
code/#committing-guidelines the guidelines].

e.g `Fixed #24352 -- Prevented ManyRelatedManager from raising an
exception when converted to string.`

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:7>

Django

unread,
Feb 23, 2015, 5:20:27 PM2/23/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

In my PR against master I see that alot files have been changed, this is
because I'm comparing 1.7 branch against master. Is this normal? I guess
not. I tried several ways to just make a PR against master with just my
change but I cannot do it. Thanks a lot for the help.

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:8>

Django

unread,
Feb 23, 2015, 5:48:47 PM2/23/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

You need to branch off of master, apply your patch, then create a pull
request with that branch.

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:9>

Django

unread,
Feb 24, 2015, 6:51:56 PM2/24/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

Replying to [comment:9 timgraham]:


> You need to branch off of master, apply your patch, then create a pull
request with that branch.

Thanks for the help. But still don't get it. Is there a documentation
about this? First how I create a branch off of master?. I just did
{{{
git checkout -b ticket_24352_1_7 master
}}}
Is that correct?
If I made the change in that repository the test will fail because the
change is for 1.7 branch.

I'm a bit frustated with this :(

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:10>

Django

unread,
Feb 24, 2015, 7:57:21 PM2/24/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

I think you're on the right track. How does the test fail? Is the bug not
present on master?

[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/working-with-git/ Working with Git/GitHub docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:11>

Django

unread,
Feb 25, 2015, 4:51:33 AM2/25/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

Yes, I think the bug is 1.7 specific. I try running this test in
m2m_regress on master branch.

{{{
def test_many_related_manager_str(self):
c1 = TagCollection.objects.create(name='c1')
self.assertIn('ManyRelatedManager', str(c1.tags))
}}}

But always get an error related to:

{{{
Traceback (most recent call last):
File "/home/alucard/workspace/Code/django/tests/m2m_regress/tests.py",
line 117, in test_many_related_manager_str
self.assertIn('ManyRelatedManager', str(c1.tags))
AssertionError: u'ManyRelatedManager' not found in 'm2m_regress.Tag.None'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:12>

Django

unread,
Feb 26, 2015, 3:58:11 AM2/26/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: assigned
Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by gmunumel):

New PR:
https://github.com/django/django/commit/798ed6f8aab97841d89e4659dbe74c9d35089b79

Let me know if it's ok.

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:13>

Django

unread,
Feb 26, 2015, 11:05:42 AM2/26/15
to django-...@googlegroups.com
#24352: Coercing ManyRelatedManager to string raises StopIteration exception
-------------------------------------+-------------------------------------
Reporter: rasca | Owner: gmunumel
Type: Bug | Status: closed

Component: Database layer | Version: 1.7
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0831a43c3afc3f93b8ed0c58630836e38248be12"]:
{{{
#!CommitTicketReference repository=""
revision="0831a43c3afc3f93b8ed0c58630836e38248be12"
[1.7.x] Fixed #24352 -- Fixed crash when coercing ``ManyRelatedManager``
to a string.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24352#comment:14>

Reply all
Reply to author
Forward
0 new messages