﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35111	DateField's __range and __in lookups against expressions produce invalid values on SQLite.	Simon Charette	Simon Charette	"#22288 (4f138fe5a496a81115c4fba6615a517fc62c3b17) only partially addressed the issue of iterable right-hand-side lookups (`__range` and `__in`) by adapting Oracle's and SQLite operation modules to special case the adaptation of datetime and time value while missing that date values are still converted to string.

This causes queries of the form

{{{#!python
Person.objects.filter(
    dob__between=(F(""dob""), F(""dob""))
)
}}}

To be turned into

{{{#!sql
SELECT * FROM person WHERE dob BETWEEN ""Col('dob')"" AND ""Col('dob')""
}}}

I believe the fundamental flaw in 4f138fe5a496a81115c4fba6615a517fc62c3b17 is that expressions (`hasattr(obj, ""resolve_expression"")`) should never be passed to `Field.get_db_prep_value` in the first place during the `Lookup`'s right-hand-side ''processing'' phase just like they are not passed to `Field.get_prep_value` [https://github.com/django/django/blob/92d6cff6a2fee7a3f9244081b84fd82c50cc71aa/django/db/models/lookups.py#L287-L295 during the preparation phase].

Initially discovered on [https://forum.djangoproject.com/t/range-lookup-with-complex-expressions/26795/7 the forum] by Joel Feiner."	Bug	closed	Database layer (models, ORM)	5.0	Normal	fixed			Ready for checkin	1	0	0	0	0	0
