From faeb92ea13f0c1b2cc83f45b512f2c41cfb4f02d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 8 Mar 2024 11:50:11 +0000 Subject: [PATCH] Fixed #35270 -- Optimized model's Options._property_names. co-authored-by: Nick Pope --- django/db/models/options.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/django/db/models/options.py b/django/db/models/options.py index 6f08feec25..f842faf0da 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -1,6 +1,5 @@ import bisect import copy -import inspect from collections import defaultdict from django.apps import apps @@ -969,11 +968,13 @@ class Options: @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