@@ -309,7 +309,7 @@ def score_field(self) -> str:
309
309
class ExpressionProxy :
310
310
def __init__ (self , field : ModelField , parents : List [Tuple [str , "RedisModel" ]]):
311
311
self .field = field
312
- self .parents = parents
312
+ self .parents = parents . copy () # Ensure a copy is stored
313
313
314
314
def __eq__ (self , other : Any ) -> Expression : # type: ignore[override]
315
315
return Expression (
@@ -387,13 +387,14 @@ def __getattr__(self, item):
387
387
attr = getattr (embedded_cls , item )
388
388
else :
389
389
attr = getattr (outer_type , item )
390
+
390
391
if isinstance (attr , self .__class__ ):
392
+ # Clone the parents to ensure isolation
393
+ new_parents = self .parents .copy ()
391
394
new_parent = (self .field .alias , outer_type )
392
- if new_parent not in attr .parents :
393
- attr .parents .append (new_parent )
394
- new_parents = list (set (self .parents ) - set (attr .parents ))
395
- if new_parents :
396
- attr .parents = new_parents + attr .parents
395
+ if new_parent not in new_parents :
396
+ new_parents .append (new_parent )
397
+ attr .parents = new_parents
397
398
return attr
398
399
399
400
@@ -632,10 +633,11 @@ def resolve_value(
632
633
value : Any ,
633
634
parents : List [Tuple [str , "RedisModel" ]],
634
635
) -> str :
636
+ # The 'field_name' should already include the correct prefix
637
+ result = ""
635
638
if parents :
636
639
prefix = "_" .join ([p [0 ] for p in parents ])
637
640
field_name = f"{ prefix } _{ field_name } "
638
- result = ""
639
641
if field_type is RediSearchFieldTypes .TEXT :
640
642
result = f"@{ field_name } _fts:"
641
643
if op is Operators .EQ :
@@ -792,8 +794,6 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:
792
794
793
795
if expression .op is Operators .ALL :
794
796
if encompassing_expression_is_negated :
795
- # TODO: Is there a use case for this, perhaps for dynamic
796
- # scoring purposes with full-text search?
797
797
raise QueryNotSupportedError (
798
798
"You cannot negate a query for all results."
799
799
)
@@ -827,6 +827,11 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:
827
827
f"or an expression enclosed in parentheses. Docs: { ERRORS_URL } #E7"
828
828
)
829
829
830
+ if isinstance (expression .left , ModelField ) and expression .parents :
831
+ # Build field_name using the specific parents for this expression
832
+ prefix = "_" .join ([p [0 ] for p in expression .parents ])
833
+ field_name = f"{ prefix } _{ field_name } "
834
+
830
835
right = expression .right
831
836
832
837
if isinstance (right , Expression ) or isinstance (right , NegatedExpression ):
@@ -842,8 +847,6 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:
842
847
843
848
if isinstance (right , NegatedExpression ):
844
849
result += "-"
845
- # We're handling the RediSearch operator in this call ("-"), so resolve the
846
- # inner expression instead of the NegatedExpression.
847
850
right = right .expression
848
851
849
852
result += f"({ cls .resolve_redisearch_query (right )} )"
0 commit comments