pypika
pypika copied to clipboard
ComplexCriterion does not use aliases
It appears that ComplexCriterion ignores an alias attached to it. From the code I can see that other criteria have a signature like def get_sql(self, with_alias: bool = False, ...), but ComplexCriterion lacks that handling of with_alias.
Consequently, when I do something like
.select((criterion_1 | criterion_2).as_("my_alias"))
the SQL version will not include that my_alias.
I was just bitten by this.
A workaround solution for now.
from pypika.utils import format_alias_sql
try:
_original_ComplexCriterion_get_sql
except NameError:
_original_ComplexCriterion_get_sql = ComplexCriterion.get_sql
def _patched_get_sql(self, *args, **kwargs):
return format_alias_sql(
_original_ComplexCriterion_get_sql(self, *args, **kwargs), self.alias, **kwargs)
ComplexCriterion.get_sql = _patched_get_sql
see https://github.com/kayak/pypika/pull/735