Skip to content

feat: improve SQL validation for aggregate functions and entity model resilience#1571

Open
UIPath-Harshit wants to merge 1 commit intomainfrom
feat/entities-sql-validation-improvements
Open

feat: improve SQL validation for aggregate functions and entity model resilience#1571
UIPath-Harshit wants to merge 1 commit intomainfrom
feat/entities-sql-validation-improvements

Conversation

@UIPath-Harshit
Copy link
Copy Markdown
Contributor

Summary

  • Add aggregate function detection (COUNT, SUM, AVG, MIN, MAX) so queries using aggregates are allowed without WHERE/LIMIT clauses
  • Block COUNT(*) with a clear error message directing users to use COUNT(column_name) instead
  • Require a FROM clause in all queries
  • Refactor projection parsing from flattened tokens to AST nodes for accurate column counting and bare-wildcard detection
  • Make Entity model more resilient: optional SourceJoinCriteria fields, AliasChoices for sourceJoinCriterias/sourceJoinCriteria, union types for externalFields, and optional reference_type in FieldMetadata
  • Bump uipath-platform version to 0.1.29

Test plan

  • Existing entity service tests pass
  • New test cases for aggregate queries (COUNT, SUM, AVG, MIN, MAX) pass validation
  • New test cases for COUNT(*) rejection, missing FROM, and non-aggregate functions (UPPER, COALESCE) are validated
  • Lint and format checks pass

🤖 Generated with Claude Code

@github-actions github-actions bot added the test:uipath-langchain Triggers tests in the uipath-langchain-python repository label Apr 16, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8c5a5b903

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1408 to +1411
if isinstance(node, IdentifierList):
for child in node.tokens:
if child.ttype is Wildcard:
return True
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Treat qualified table.* as disallowed wildcard

_projection_has_bare_wildcard only checks tokens whose type is Wildcard directly or inside an IdentifierList, but it never inspects Identifier nodes. In sqlparse, table.* is represented as an Identifier, so queries like SELECT Customers.* FROM Customers LIMIT 10 bypass the SELECT * without filtering guard and also slip past the >4 columns limit because _projection_column_count treats that projection as one column. This reopens unrestricted full-row reads that the validator is meant to block.

Useful? React with 👍 / 👎.

@UIPath-Harshit UIPath-Harshit force-pushed the feat/entities-sql-validation-improvements branch 2 times, most recently from 4c645af to 2b0a8e0 Compare April 16, 2026 12:21
@UIPath-Harshit UIPath-Harshit force-pushed the feat/entities-sql-validation-improvements branch from cde1447 to d4ddc56 Compare April 17, 2026 10:37
… resilience

Add aggregate function detection (COUNT, SUM, AVG, MIN, MAX) to allow
queries without WHERE/LIMIT clauses. Block COUNT(*) with a clear error
message. Refactor projection parsing to use AST nodes instead of flattened
tokens for more accurate column counting and wildcard detection. Make
Entity model fields more resilient with optional SourceJoinCriteria fields,
AliasChoices for sourceJoinCriterias, and union types for externalFields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@UIPath-Harshit UIPath-Harshit force-pushed the feat/entities-sql-validation-improvements branch from 2e3e5c4 to 38e4438 Compare April 17, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant