Build a WhereNode for a single filter clause but don't add it to this Query. Query.add_q() will then add this filter to the where Node. The 'branch_negated' tells us if the current branch contains any negations. This will be used to determine if subqueries a
(
self,
filter_expr,
branch_negated=False,
current_negated=False,
can_reuse=None,
allow_joins=True,
split_subq=True,
check_filterable=True,
summarize=False,
update_join_types=True,
)
| 1485 | ) |
| 1486 | |
| 1487 | def build_filter( |
| 1488 | self, |
| 1489 | filter_expr, |
| 1490 | branch_negated=False, |
| 1491 | current_negated=False, |
| 1492 | can_reuse=None, |
| 1493 | allow_joins=True, |
| 1494 | split_subq=True, |
| 1495 | check_filterable=True, |
| 1496 | summarize=False, |
| 1497 | update_join_types=True, |
| 1498 | ): |
| 1499 | """ |
| 1500 | Build a WhereNode for a single filter clause but don't add it |
| 1501 | to this Query. Query.add_q() will then add this filter to the where |
| 1502 | Node. |
| 1503 | |
| 1504 | The 'branch_negated' tells us if the current branch contains any |
| 1505 | negations. This will be used to determine if subqueries are needed. |
| 1506 | |
| 1507 | The 'current_negated' is used to determine if the current filter is |
| 1508 | negated or not and this will be used to determine if IS NULL filtering |
| 1509 | is needed. |
| 1510 | |
| 1511 | The difference between current_negated and branch_negated is that |
| 1512 | branch_negated is set on first negation, but current_negated is |
| 1513 | flipped for each negation. |
| 1514 | |
| 1515 | Note that add_filter will not do any negating itself, that is done |
| 1516 | upper in the code by add_q(). |
| 1517 | |
| 1518 | The 'can_reuse' is a set of reusable joins for multijoins. |
| 1519 | |
| 1520 | The method will create a filter clause that can be added to the current |
| 1521 | query. However, if the filter isn't added to the query then the caller |
| 1522 | is responsible for unreffing the joins used. |
| 1523 | """ |
| 1524 | if isinstance(filter_expr, dict): |
| 1525 | raise FieldError("Cannot parse keyword query as dict") |
| 1526 | if isinstance(filter_expr, Q): |
| 1527 | return self._add_q( |
| 1528 | filter_expr, |
| 1529 | branch_negated=branch_negated, |
| 1530 | current_negated=current_negated, |
| 1531 | used_aliases=can_reuse, |
| 1532 | allow_joins=allow_joins, |
| 1533 | split_subq=split_subq, |
| 1534 | check_filterable=check_filterable, |
| 1535 | summarize=summarize, |
| 1536 | update_join_types=update_join_types, |
| 1537 | ) |
| 1538 | if hasattr(filter_expr, "resolve_expression"): |
| 1539 | if not getattr(filter_expr, "conditional", False): |
| 1540 | raise TypeError("Cannot filter against a non-conditional expression.") |
| 1541 | condition = filter_expr.resolve_expression( |
| 1542 | self, allow_joins=allow_joins, reuse=can_reuse, summarize=summarize |
| 1543 | ) |
| 1544 | if not isinstance(condition, Lookup): |
no test coverage detected