Skip to content

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

Merged
UIPath-Harshit merged 2 commits intomainfrom
feat/entities-sql-validation-improvements-v2
Apr 20, 2026
Merged

feat: improve SQL validation for aggregate functions and entity model resilience#1576
UIPath-Harshit merged 2 commits intomainfrom
feat/entities-sql-validation-improvements-v2

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.32

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

… 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>
@github-actions github-actions Bot added the test:uipath-langchain Triggers tests in the uipath-langchain-python repository label Apr 20, 2026
@UIPath-Harshit UIPath-Harshit marked this pull request as ready for review April 20, 2026 07:14
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: b57049dc10

ℹ️ 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 thread packages/uipath-platform/src/uipath/platform/entities/_entities_service.py Outdated
Comment on lines +1394 to +1397
if isinstance(node, (Identifier, IdentifierList)):
for child in node.tokens:
if isinstance(child, Function) and _is_count_star(child):
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 Detect COUNT(*) inside aliased IdentifierList items

The COUNT(*) guard has the same traversal gap for IdentifierList: it checks direct Function children only and misses Identifier items that wrap aliased functions. As a result, forms like SELECT COUNT(*) AS total, COUNT(id) AS c FROM Customers LIMIT 10 can bypass the explicit COUNT(*) prohibition, even though this commit intends to block COUNT(*) universally.

Useful? React with 👍 / 👎.

…T(*)

Aliased function expressions (e.g. COUNT(id) AS total) are parsed as
Identifier > Function by sqlparse. The previous checks only looked at
direct Function children, missing these cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@UIPath-Harshit UIPath-Harshit force-pushed the feat/entities-sql-validation-improvements-v2 branch from c33c645 to f08bed1 Compare April 20, 2026 10:19
@UIPath-Harshit UIPath-Harshit merged commit 9682896 into main Apr 20, 2026
122 checks passed
@UIPath-Harshit UIPath-Harshit deleted the feat/entities-sql-validation-improvements-v2 branch April 20, 2026 10:29
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.

2 participants