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.

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
12 from copy import copy
23 from typing import Any, Optional, Union
34
485486 for field in term.fields_():
486487 if not any([self._insert_table, self._update_table, self._delete_from]):
487488 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:
489495 raise QueryException("You can't return from other tables")
490496
491497 def _set_returns_for_star(self) -> None:

The check that tells the two apart

failpass·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