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

RESOLVED FIXED

Status

Tree Management
Treeherder
P1
normal
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: chmanchester, Assigned: camd)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
Created attachment 8650763 [details]
Screenshot from 2015-08-20 16:24:48.png

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.

Comment 1

3 years ago
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'")

Comment 3

3 years ago
(Meant to say: that same blog article suggests using prefetch-related instead:
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#prefetch-related )

Comment 4

3 years ago
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)

Updated

3 years ago
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)

Comment 6

3 years ago
(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) :-)
(Assignee)

Comment 7

3 years ago
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.
(Assignee)

Updated

3 years ago
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.