Closed symbiosdotwiki closed 9 years ago
Could you provide more information so that we can reproduce ? Maybe isolate the bug in a new app in the test_project so that we can work on it ? Thanks !
@jpic Its really just the basic example:
#models.py
class Subject(models.Model):
subject_type = models.ForeignKey(SubjectType)
name = models.CharField(max_length = 100)
def __unicode__(self):
return unicode(self.subject_type) + ": " + unicode(self.name)
#autocomplete_light_registry.py
import autocomplete_light
from models import Subject
class SubjectAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['name',]
autocomplete_light.register(Subject)
#admin.py
import autocomplete_light
autocomplete_light.autodiscover()
............
class TutorStudentSubjectRateInline(admin.TabularInline):
model = TutorStudentSubjectRate
extra = 0
form = autocomplete_light.modelform_factory(TutorStudentSubjectRate, fields = '__all__')
the autocomplete works fine, but it can't be saved once you choose the thing
also the expanded traceback:
/usr/local/lib/python2.7/dist-packages/django/db/utils.py in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback) ...
▼ Local vars
Variable Value
self
<django.db.utils.DatabaseErrorWrapper object at 0x7f8aa2d81810>
traceback
<traceback object at 0x7f8aa2c8ccf8>
exc_type
<class 'psycopg2.ProgrammingError'>
dj_exc_type
<class 'django.db.utils.ProgrammingError'>
dj_exc_value
ProgrammingError('missing FROM-clause entry for table "subjects_subject"\nLINE 1: SELECT (CASE WHEN Subjects_subject.id=\'3\' THEN 0 END) AS "or...\n ^\n',)
exc_value
ProgrammingError('missing FROM-clause entry for table "subjects_subject"\nLINE 1: SELECT (CASE WHEN Subjects_subject.id=\'3\' THEN 0 END) AS "or...\n ^\n',)
db_exc_type
<class 'psycopg2.ProgrammingError'>
/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py in execute
return self.cursor.execute(sql, params) ...
▼ Local vars
Variable Value
self
<django.db.backends.utils.CursorDebugWrapper object at 0x7f8aa2c81c10>
params
(3,)
sql
u'SELECT (CASE WHEN Subjects_subject.id=\'3\' THEN 0 END) AS "ordering", "Subjects_subject"."id", "Subjects_subject"."subject_type_id", "Subjects_subject"."name" FROM "Subjects_subject" WHERE "Subjects_subject"."id" IN (%s) ORDER BY "ordering" ASC'
I get the same error for basic Admin for the same model as well
Could you fix formating of your comments please ? Thanks
@jpic all fixed, sorry.
I literally followed the super basic first example to just register a model and autocomplete in another model's admin, I don't know why I am getting sql errors...
Any news on this?
Ok, you meant you "all fixed" the formatting only ^^
What PG version is this ?
I understand from the error that there is a reference to the subjects_subject
table which fails because in the FROM clause we're selecting from the Subjects_subject
table. However, I don't see where the query is referring to subjects_subject
, all I can see apparently is reference to Subjects_subject
which is appropriately in the FROM clause:
u'SELECT (CASE WHEN Subjects_subject.id=\'3\' THEN 0 END) AS "ordering", "Subjects_subject"."id", "Subjects_subject"."subject_type_id", "Subjects_subject"."name" FROM "Subjects_subject" WHERE "Subjects_subject"."id" IN (%s) ORDER BY "ordering" ASC'
Maybe it's converting the first one, Subjects_subject
from the CASE WHEN
to lowercase. Could you try this query and report what happens ? Does it work better with "Subjects_subject"."id"
instead of Subjects_subject.id
(note the absence of double quote "
).
Thanks !
Confirmed, that really seems to be the bug:
jpic=> create table "Bar" ( id int primary key, name varchar (100));
CREATE TABLE
jpic=> select Bar.id from "Bar";
ERROR: missing FROM-clause entry for table "bar"
LINE 1: select Bar.id from "Bar";
^
jpic=> select "Bar".id from "Bar";
┌────┐
│ id │
├────┤
└────┘
(0 rows)
Closing in favor of PR #452, please review it and let us know if it works for you. Thanks !
Awesome! I'm glad my terrible naming practices helped to find such a strange case.
This would have taken me forever to find/fix, thanks!
Thanks for the kind words, I'm a bit anal about naming myself so maybe that did help xD
PR in question is #464, not #452.
Fix released in 2.2.5
I have no real idea why this would be breaking, I am just using a simple autocomplete in an inline and getting this error
any help is appreciate, here is traceback
Environment: