Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mm committed Jan 19, 2024
2 parents f2aa09e + 4879907 commit 7ac4223
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/static/admin/img/icon-addlink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion django/contrib/admin/static/admin/img/icon-changelink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ def clean_fields(self, exclude=None):

errors = {}
for f in self._meta.fields:
if f.name in exclude:
if f.name in exclude or f.generated:
continue
# Skip validation for empty fields with blank=True. The developer
# is responsible for making sure they have a valid value.
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/5.0.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Bugfixes

* Fixed a regression in Django 5.0 where links in the admin had an incorrect
color (:ticket:`35121`).

* Fixed a bug in Django 5.0 that caused a crash of ``Model.full_clean()`` on
models with a ``GeneratedField`` (:ticket:`35127`).
4 changes: 2 additions & 2 deletions tests/model_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class GeneratedModel(models.Model):
output_field=models.IntegerField(),
db_persist=True,
)
fk = models.ForeignKey(Foo, on_delete=models.CASCADE, null=True)
fk = models.ForeignKey(Foo, on_delete=models.CASCADE, null=True, blank=True)

class Meta:
required_db_features = {"supports_stored_generated_columns"}
Expand All @@ -516,7 +516,7 @@ class GeneratedModelVirtual(models.Model):
output_field=models.IntegerField(),
db_persist=False,
)
fk = models.ForeignKey(Foo, on_delete=models.CASCADE, null=True)
fk = models.ForeignKey(Foo, on_delete=models.CASCADE, null=True, blank=True)

class Meta:
required_db_features = {"supports_virtual_generated_columns"}
Expand Down
8 changes: 8 additions & 0 deletions tests/model_fields/test_generatedfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def test_unsaved_error(self):
with self.assertRaisesMessage(AttributeError, msg):
m.field

def test_full_clean(self):
m = self.base_model(a=1, b=2)
# full_clean() ignores GeneratedFields.
m.full_clean()
m.save()
m = self._refresh_if_needed(m)
self.assertEqual(m.field, 3)

def test_create(self):
m = self.base_model.objects.create(a=1, b=2)
m = self._refresh_if_needed(m)
Expand Down

0 comments on commit 7ac4223

Please sign in to comment.