Opened 5 years ago

Closed 5 years ago

#24352 closed Bug (fixed)

Coercing ManyRelatedManager to string raises StopIteration exception

Reported by: rasca Owned by: Gabriel Muñumel
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Change History (14)

comment:1 Changed 5 years ago by Tim Graham

Easy pickings: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by Gabriel Muñumel

Owner: changed from nobody to Gabriel Muñumel
Status: newassigned

comment:3 Changed 5 years ago by Gabriel Muñumel

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.

comment:4 Changed 5 years ago by Simon Charette

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

comment:5 in reply to:  4 Changed 5 years ago by Gabriel Muñumel

Replying to 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?

comment:6 Changed 5 years ago by Gabriel Muñumel

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?

comment:7 Changed 5 years ago by Simon Charette

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

Yes, but per our 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 the guidelines.

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

comment:8 Changed 5 years ago by Gabriel Muñumel

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.

comment:9 Changed 5 years ago by Tim Graham

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

comment:10 in reply to:  9 Changed 5 years ago by Gabriel Muñumel

Replying to 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 :(

comment:11 Changed 5 years ago by Tim Graham

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

Working with Git/GitHub docs.

comment:12 Changed 5 years ago by Gabriel Muñumel

Replying to timgraham:

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'
Last edited 5 years ago by Gabriel Muñumel (previous) (diff)

comment:14 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 0831a43c3afc3f93b8ed0c58630836e38248be12:

[1.7.x] Fixed #24352 -- Fixed crash when coercing ManyRelatedManager to a string.

Note: See TracTickets for help on using tickets.
Back to Top