Skip to content

Conversation

@seer-by-sentry
Copy link

@seer-by-sentry seer-by-sentry bot commented Nov 4, 2025

Fixes SNUBA-5VG. The issue was that: ClickHouse SQL formatter incorrectly applies leading hyphen alias to generic NOT function call, causing syntax error.

  • Adds support for the NOT function in the ClickHouse expression formatter.
  • Formats the NOT function without applying an alias to prevent malformed SQL when the inner expression has an alias starting with special characters.

This fix was generated by Seer in Sentry, triggered by [email protected]. 👁️ Run ID: 2410387

Not quite right? Click here to continue debugging with Seer.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@seer-by-sentry seer-by-sentry bot requested a review from a team as a code owner November 4, 2025 17:03
Comment on lines +160 to +164
# Format NOT function without applying alias to avoid malformed SQL
# when the inner expression has an alias starting with special characters
formatted = self.__visit_params(exp.parameters)
return f"not({formatted})"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: New code for BooleanFunctions.NOT silently drops aliases from FunctionCall objects during formatting.
Severity: HIGH | Confidence: 0.95

🔍 Detailed Analysis

When a FunctionCall object with function_name == "not" and a non-null alias is processed by the formatter, the alias is silently dropped. This occurs because the new code introduced for BooleanFunctions.NOT in snuba/clickhouse/formatter/expression.py:160~164 does not include a call to self._alias(ret, exp.alias), unlike other function calls. This omission results in the alias information, which is present in the query AST and actively used in production code (e.g., snuba/query/processors/physical/empty_tag_condition_processor.py), not being applied to the formatted output.

💡 Suggested Fix

After formatting the NOT expression, ensure self._alias(ret, exp.alias) is called to apply the alias, consistent with how other function calls are handled in the formatter.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: snuba/clickhouse/formatter/expression.py#L160-L164

Potential issue: When a `FunctionCall` object with `function_name == "not"` and a
non-null `alias` is processed by the formatter, the alias is silently dropped. This
occurs because the new code introduced for `BooleanFunctions.NOT` in
`snuba/clickhouse/formatter/expression.py:160~164` does not include a call to
`self._alias(ret, exp.alias)`, unlike other function calls. This omission results in the
alias information, which is present in the query AST and actively used in production
code (e.g., `snuba/query/processors/physical/empty_tag_condition_processor.py`), not
being applied to the formatted output.

Did we get this right? 👍 / 👎 to inform future reviews.

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

Successfully merging this pull request may close these issues.

1 participant