Skip to content

Fix with_alias argument in terms classes #616

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

Open
AnghileriDavide opened this issue Jul 13, 2021 · 3 comments
Open

Fix with_alias argument in terms classes #616

AnghileriDavide opened this issue Jul 13, 2021 · 3 comments

Comments

@AnghileriDavide
Copy link

Hi, I noticed that some terms do not use the with_alias parameter in the get_sql() function always returning the sql string formatted with alias even if the with_alias parameter is set to false. I was wondering if there is a reason to have some terms with this behavior or if the logic is missing in some terms.

The problem is that if the alias is used in the WHERE clause of a SQL query it breaks

For example the get_sql() function of the term class NullCriterion(Criterion) is defined as follows:

def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
    sql = "{term} IS NULL".format(
        term=self.term.get_sql(**kwargs),
    )
    return format_alias_sql(sql, self.alias, **kwargs)

Shouldn't be more correct to have:

def get_sql(self, with_alias: bool = False, **kwargs: Any) -> str:
    sql = "{term} IS NULL".format(
        term=self.term.get_sql(**kwargs),
    )
    if with_alias:
        return format_alias_sql(sql, self.alias, **kwargs)
    return sql

The same applies for other terms like BetweenCriterion, BitwiseAndCriterion, NullCriterion and others

@AnghileriDavide AnghileriDavide changed the title Fix with_alias in terms Fix with_alias argument in terms classes Jul 13, 2021
@Ga68
Copy link

Ga68 commented Jul 6, 2023

I ran into the same problem. And sadly this great package seems to have gone quiet, so I'm guessing no changes are going to get pulled in. Thus, I fixed it for myself. I tested it out, albeit lightly, and it seems to be working in that the alias is still present for the SELECT clauses, but removed in the WHERE clauses. Maybe it'll help you.

@Ga68
Copy link

Ga68 commented Jul 7, 2023

see #735

@AzisK
Copy link

AzisK commented Sep 7, 2023

Hello, I inherited this package and will now take care of it. Thank you for raising the issues and finding solutions to them

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