Closed Bug 1196998 Opened 9 years ago Closed 9 years ago

Error adding exclusion profile after update to Django 1.8 ("Non-relational field given in select_related: 'info'")

Categories

(Tree Management :: Treeherder, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: chmanchester, Assigned: camd)

References

Details

Attachments

(1 file)

I was trying to hide the GTest job I added in bug 1196464 and got the attached error. Not sure what's going on here, but the job is visible on try (and red) for now.
This seems to be a Django 1.8 update regression:
https://docs.djangoproject.com/en/1.8/releases/1.8/#select-related-now-checks-given-fields

select_related() now validates that the given fields actually exist. Previously, nonexistent fields were silently ignored. Now, an error is raised:
...

The validation also makes sure that the given field is relational:

>>> book = Book.objects.select_related('name')
Traceback (most recent call last):
...
FieldError: Non-relational field given in select_related: 'name'
Blocks: 1181879
Flags: needinfo?(mdoglio)
Priority: -- → P1
Summary: Error attempting to add to exclusion profile → Error adding exclusion profile after update to Django 1.8 ("Non-relational field given in select_related: 'info'")
(Meant to say: that same blog article suggests using prefetch-related instead:
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#prefetch-related )
Commit pushed to master at https://github.com/mozilla/treeherder

https://github.com/mozilla/treeherder/commit/c8c84e3d1a15dbe65e88e68d300a925e5322a2ba
Bug 1196998 - Error adding exclusion profile after update to Django 1.8

We were calling select_related on a non-relational field.  Only became
an issue with Django 1.8.
Assignee: nobody → cdawson
:emorley the line you highlighted is defining a ManyToMany field. The `related_name` parameter is the name of the attribute the related class will use to refer to this one. I didn't know about the prefetch_related method, they must have added it in the last couple of versions of django :-)
Flags: needinfo?(mdoglio)
(In reply to Mauro Doglio [:mdoglio] from comment #5)
> :emorley the line you highlighted is defining a ManyToMany field. The
> `related_name` parameter is the name of the attribute the related class will
> use to refer to this one. I didn't know about the prefetch_related method,
> they must have added it in the last couple of versions of django :-)

I'm not sure I understand this reply? Do you mean the current fix here was correct, or not? (It actually doesn't use prefetch_related, it removes select_related entirely) :-)
I'm pretty sure just removing that was the right call.  But feel free to double-check me, if I'm missing something.  :)

The self.exclusions.all() is fetching all the rows of the JobExclusion model.  The field of ``info`` is in that model.  It's not a foreign key or a m2m relation.  It was just superfluous.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: