Skip to content

Commit

Permalink
Fixed #35270 -- Optimized model's Options._property_names.
Browse files Browse the repository at this point in the history
co-authored-by: Nick Pope <nick@nickpope.me.uk>
  • Loading branch information
2 people authored and felixxm committed Mar 9, 2024
1 parent 73df8b5 commit faeb92e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions django/db/models/options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import bisect
import copy
import inspect
from collections import defaultdict

from django.apps import apps
Expand Down Expand Up @@ -969,11 +968,13 @@ def total_unique_constraints(self):
@cached_property
def _property_names(self):
"""Return a set of the names of the properties defined on the model."""
names = []
for name in dir(self.model):
attr = inspect.getattr_static(self.model, name)
if isinstance(attr, property):
names.append(name)
names = set()
for klass in self.model.__mro__:
names |= {
name
for name, value in klass.__dict__.items()
if isinstance(value, property)
}
return frozenset(names)

@cached_property
Expand Down

0 comments on commit faeb92e

Please sign in to comment.