Whole file
kayak/pypika
The author described this change as “Fix PostgreSQLQueryBuilder returning clause code causing Py3.9 test failures”. It counts as a record because the check below fails on the code as it stood at 1e2104eae and passes on 217060873, with nothing else changed between the two runs.
Projectkayak/pypika
Fix saved2021-01-04
Sharing licenceApache-2.0 · LICENSE.txt
Change size+7 −1
What the code was meant to do, written into the code itself as a save note
Fix PostgreSQLQueryBuilder returning clause code causing Py3.9 test failures
The change
| 1 | + | import itertools | |
| 1 | 2 | from copy import copy | |
| 2 | 3 | from typing import Any, Optional, Union | |
| 3 | 4 | ||
| ⋯ | |||
| 485 | 486 | for field in term.fields_(): | |
| 486 | 487 | if not any([self._insert_table, self._update_table, self._delete_from]): | |
| 487 | 488 | raise QueryException("Returning can't be used in this query") | |
| 488 | - | if field.table not in {self._insert_table, self._update_table} and term not in self._from: | |
| 489 | + | ||
| 490 | + | table_is_insert_or_update_table = field.table in {self._insert_table, self._update_table} | |
| 491 | + | join_tables = set(itertools.chain.from_iterable([j.criterion.tables_ for j in self._joins])) | |
| 492 | + | join_and_base_tables = set(self._from) | join_tables | |
| 493 | + | table_not_base_or_join = bool(term.tables_ - join_and_base_tables) | |
| 494 | + | if not table_is_insert_or_update_table and table_not_base_or_join: | |
| 489 | 495 | raise QueryException("You can't return from other tables") | |
| 490 | 496 | ||
| 491 | 497 | def _set_returns_for_star(self) -> None: | |
The check that tells the two apart
fail→pass·pypika/tests/dialects/test_postgresql.py::ReturningClauseTests::test_return_field_from_join_table
Check file pypika/tests/dialects/test_postgresql.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1e2104eae8a282d7d7a9b56ed7a62f94eb14f830
Broken version dated2020-12-09
Modulepypika.dialects
Units changedPostgreSQLQueryBuilder
Fingerprint1c354bef59c24f58
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in kayak/pypika
- 2024-04-17fix `Field.__init__` (#742)
- 2023-09-26Fix: Allow the usage of `frozenset` in the `isin(...)` and `notin(...)` functions (#744)
- 2023-09-22fix(terms): fixed EmptyCriterion bug with ComplexCriterion (#732)
- 2021-08-26MySQLQuery
- 2021-01-11Fix empty Postgres array syntax (#539)
- 2020-12-09Fix groupby_alias specified multiple times in kwargs when subqueries are used