Skip to content

Fix with_alias argument in terms classes #616

@AnghileriDavide

Description

@AnghileriDavide

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions