You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using `RawSQL` with `model._meta.pk.db_column` will add a verbatim SQL expression into the query. In this case, a reference to the primary key column, although without the proper table alias. This leads to a SQL error for QuerySets which already have a JOIN due to an ambiguous column (e.g. `id`).
Use Django's `Cast` function with the `id` property to cast the primary key of the model into a string, which will automatically de-alias `pk` to the name of primary key field and use the correct table alias in the resulting query.
The Cast call will use a TextField as the output, although CharField (to cast into a varchar) ought to be enough.
I've left do_string_cast in place. It's unused now, but someone may rely on it being present in the backend implementation.
It would be great to have this fix merged and released since it's blocking our search. Thanks!
https://github.com/etianen/django-watson/blob/master/watson/search.py#L568 creates a unqualified Cast for the primary key column, which fails if the QuerySet has JOINs (e.g. because it's already filtered):
The Cast should use
U0.id
as the column selector.The text was updated successfully, but these errors were encountered: