Skip to content

Commit

Permalink
Fixed #35301 -- Fixed Options._property_names for overriden properties.
Browse files Browse the repository at this point in the history
Regression in faeb92e.
  • Loading branch information
adamchainz committed Mar 17, 2024
1 parent b07e2d5 commit 7646b90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion django/db/models/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,12 +969,14 @@ def total_unique_constraints(self):
def _property_names(self):
"""Return a set of the names of the properties defined on the model."""
names = set()
seen = set()
for klass in self.model.__mro__:
names |= {
name
for name, value in klass.__dict__.items()
if isinstance(value, property)
if isinstance(value, property) and name not in seen
}
seen |= set(klass.__dict__)
return frozenset(names)

@cached_property
Expand Down
11 changes: 11 additions & 0 deletions tests/invalid_models_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,17 @@ class Model(models.Model):
],
)

def test_inherited_overriden_property_no_clash(self):
class Cheese:
@property
def filling_id(self):
pass

class Sandwich(Cheese, models.Model):
filling = models.ForeignKey("self", models.CASCADE)

self.assertEqual(Sandwich.check(), [])

def test_single_primary_key(self):
class Model(models.Model):
foo = models.IntegerField(primary_key=True)
Expand Down

0 comments on commit 7646b90

Please sign in to comment.