I accidentally misused this like qs.select_related before realising I was using the wrong function but the error I received was a bit confusing.
I was calling this with something like qs.select_related_fields('author') but this line https://github.com/dabapps/django-readers/blob/d70ac890d9969aa69ff4949c2b45b3108e6222b1/django_readers/qs.py#L87 calls rpartition() on it which splits on __. If there are no __ sequences found in the string then you end up with a tuple like ['', '', 'author'] and only the first field is used so the args passed down into the ORM produce an error along the lines of Field '' is not valid on model x.
I reckon the solution would be to iterate over fields and raise a ValueError with the names of any fields which don't contain the __ sequence in them with an error message that probably suggests that maybe qs.select_related is what the user intended to use
I accidentally misused this like
qs.select_related
before realising I was using the wrong function but the error I received was a bit confusing.I was calling this with something like
qs.select_related_fields('author')
but this line https://github.com/dabapps/django-readers/blob/d70ac890d9969aa69ff4949c2b45b3108e6222b1/django_readers/qs.py#L87 callsrpartition()
on it which splits on__
. If there are no__
sequences found in the string then you end up with a tuple like['', '', 'author']
and only the first field is used so the args passed down into the ORM produce an error along the lines ofField '' is not valid on model x
.I reckon the solution would be to iterate over fields and raise a ValueError with the names of any fields which don't contain the
__
sequence in them with an error message that probably suggests that maybeqs.select_related
is what the user intended to use