diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 3a0c75ebf2..74ae9cab8e 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -417,6 +417,8 @@ class BaseExpression: def get_refs(self): refs = set() for expr in self.get_source_expressions(): + if expr is None: + continue refs |= expr.get_refs() return refs