﻿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
37014	SQLite emulation of db_default involving Extract/Trunc might unexpectedly apply overridden timezone for inserted values	Jacob Walls	Praful Gulani	"As developed in this [https://forum.djangoproject.com/t/extract-isnt-safe-to-use-in-db-default-on-sqlite-if-time-zone-changes-at-some-point/44781 forum post], if
- `USE_TZ = True`
- a model field uses `Extract` or `Trunc` in a `db_default` expression
- a test case uses `override_settings()` to test timezone behavior

... then in scenarios where Django must emulate the database default for SQLite in Python, the value will be transformed according to the overridden timezone setting, but this is an improper emulation, since the database's default cannot be overridden by merely flipping a Django setting.

The scenarios where Django must emulate the db default for SQLite vary depending on edges like:
- whether any field's value has been set
- whether the field with Extract/Trunc is last
- possibly: whether create() vs. bulk_create() is called
----
There are two ways to fix this as described on forum:
- introduce a heuristic (Simon: `if ddl_compiler_heuristic():`) to switch on whether to use the project default timezone or the test's overridden one
- implement `supports_default_keyword_in_insert` on SQLite by emulating it in its insert compiler

Having only thought about it today, the second approach seems like it would be simpler to implement and potentially pay broader dividends for other use cases.

Related ticket: #37013"	Bug	assigned	Database layer (models, ORM)	6.0	Normal		tzinfo, TIME_ZONE, Extract, Trunc		Accepted	1	0	0	1	0	0
