-
Notifications
You must be signed in to change notification settings - Fork 983
fix(agents-api): fix sort by updated_at query in list docs #1587
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
base: dev
Are you sure you want to change the base?
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||
|
Claude finished @Ahmad-mtos's task —— View job Analyzing PR Changes for Changelog
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Changes requested ❌
Reviewed everything up to a91db86 in 1 minute and 51 seconds. Click for details.
- Reviewed
110lines of code in2files - Skipped
0files when reviewing. - Skipped posting
2draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/agents-api/agents_api/queries/docs/list_docs.py:142
- Draft comment:
Validate the sort_by input explicitly. If sort_by is not in SORT_COLUMN_MAP, raise an HTTPException with detail "Invalid sort field" instead of risking a KeyError. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The Literal type combined with @beartype decorator on line 65 means this is already type-checked at runtime. The SORT_COLUMN_MAP keys exactly match the Literal type options. A KeyError is impossible unless there's a bug in the type checking, which is extremely unlikely. The validation would be redundant. The comment might have a point about defensive programming - what if the code is called from untyped code that bypasses the type checker? What if SORT_COLUMN_MAP is modified elsewhere? The @beartype decorator ensures runtime type checking even if called from untyped code. SORT_COLUMN_MAP is a module-level constant that matches the Literal type exactly. The suggested validation would be redundant with the existing type safety mechanisms. The code is already safe through the combination of Literal types and runtime type checking via @beartype.
2. src/agents-api/tests/test_docs_queries.py:350
- Draft comment:
Good test coverage for sorting by 'updated_at'. It verifies that documents are ordered by the latest update timestamps. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_0aJUBjqxMU2W52rz
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
|
|
||
| # Add sorting and pagination | ||
| order_column = SORT_COLUMN_MAP[sort_by] | ||
| direction_sql = "ASC" if direction == "asc" else "DESC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit validation for the sort direction. Currently, any value other than 'asc' defaults to 'DESC', but tests expect an HTTPException with "Invalid sort direction" for invalid inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed 5514730 in 46 seconds. Click for details.
- Reviewed
15lines of code in1files - Skipped
0files when reviewing. - Skipped posting
1draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/agents-api/agents_api/queries/docs/list_docs.py:141
- Draft comment:
The update consolidates the ORDER BY clause string into a single f-string for conciseness. The approach is safe because both the sort column and direction are controlled via a mapping and literals. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_187uYBSeIxsOGSQ7
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Code Review for PR #1587: Fix sort by updated_at query in list docsThank you for this PR! I have reviewed the changes and have the following feedback: ✅ Strengths
🔍 Areas for Improvement1. Security Concern in Related CodeWhile reviewing your changes, I noticed that src/agents-api/agents_api/queries/files/list_files.py:83 has a similar pattern but lacks the same security improvements: query += f" ORDER BY f.{sort_by} {direction} LIMIT ${param_index} OFFSET ${param_index + 1}"This directly interpolates sort_by and direction into the SQL query. While these are validated by Literal types, the approach in your PR is more robust. Consider applying the same pattern there in a follow-up PR. 2. Test ReliabilityThe test uses await asyncio.sleep(0.01) to ensure different timestamps. While this works, consider:
Alternative approaches:
3. Missing Edge Cases in TestsConsider adding tests for:
4. DocumentationThe function docstring in list_docs correctly lists the parameters, but consider documenting this security pattern in the directory AGENTS.md file for future reference. 💡 Suggestions
✅ VerdictThis is a well-implemented fix that properly addresses the sorting issue while improving security. The code is clean, follows project conventions, and includes appropriate tests. With the minor improvements suggested above (particularly addressing the test reliability), this PR is ready to merge. Great work on identifying and fixing this issue with a security-conscious approach! 🎉 |

User description
… functionality
PR Type
Enhancement, Tests
Description
Add
updated_atfield to docs list query and sorting functionalityImplement
SORT_COLUMN_MAPto safely map sort keys to fully-qualified columnsUse parameterized sort direction to prevent SQL injection vulnerabilities
Add regression test for sorting by
updated_atwith descending orderDiagram Walkthrough
File Walkthrough
list_docs.py
Add updated_at field and safe sort column mappingsrc/agents-api/agents_api/queries/docs/list_docs.py
updated_atfield to the base docs SELECT querySORT_COLUMN_MAPdictionary to map exposed sort keys tofully-qualified column names
parameterized direction SQL
references
test_docs_queries.py
Add regression test for updated_at sortingsrc/agents-api/tests/test_docs_queries.py
asyncioimport for sleep functionalityupdated_atfieldtimestamps
descending sort order
Important
Enhance document listing by adding
updated_atsorting and a regression test for safety and functionality.updated_atfield tolist_docs.pyfor document sorting.SORT_COLUMN_MAPto map sort keys to column names safely.test_docs_queries.pyfor sorting byupdated_atin descending order.This description was created by
for 5514730. You can customize this summary. It will automatically update as commits are pushed.