Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComplexCriterion does not use aliases #673

Open
MarkusShepherd opened this issue Mar 2, 2022 · 3 comments
Open

ComplexCriterion does not use aliases #673

MarkusShepherd opened this issue Mar 2, 2022 · 3 comments

Comments

@MarkusShepherd
Copy link

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.

@randy3k
Copy link

randy3k commented May 6, 2022

I was just bitten by this.

@randy3k
Copy link

randy3k commented May 7, 2022

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

@Ga68
Copy link

Ga68 commented Jul 7, 2023

see #735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants