﻿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
35575	Add support for constraint validation on GeneratedFields	Mark Gensler	Mark Gensler	"`GeneratedField`s on a model instance are not recalculated during `Model.full_clean()`. Therefore, if a `GeneratedField` is included in the `*expressions` or `fields` parameters of a `UniqueConstraint` or `CheckConstraint` in the instance's `Model._meta`, the new values of the `GeneratedField` attribute are not used by `BaseConstraint.validate()`.

Instead, the model instance's `GeneratedField` attribute will return the value which corresponds to the most recent refresh of the instance from the database. If the instance is new and has not yet been saved, the following error is raised:

`AttributeError: Cannot read a generated field from an unsaved model.`

An `IntegrityError` is correctly raised when calling `Model.save()` if any constraints involving `GeneratedField`s are violated.

Instead, the recalculated values for `GeneratedField`s should be used when checking constraints.

This ticket was raised after fixing the bug in #35560 with PR [https://github.com/django/django/pull/18309]."	New feature	closed	Database layer (models, ORM)	5.0	Normal	fixed	generatedfield uniqueconstraint checkconstraint	Mariusz Felisiak Lily Foote Simon Charette	Ready for checkin	1	0	0	0	0	0
