Conversation
POST /api/queries and POST /api/queries/<id> passed the user-supplied name straight to the database, so a name longer than the varchar(255) column (or a description longer than varchar(4096)) failed with StringDataRightTruncation and surfaced as a 500. Validate the lengths against the column definitions and abort with a 400 and a clear message. Fixes getredash#7478 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryThe PR prevents oversized query names and descriptions from reaching PostgreSQL by validating them against the SQLAlchemy column limits during query creation and updates.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified in the changed paths. The validation uses the current model column limits, covers both primary creation and update handlers before persistence, and is backed by focused regression tests.
|
| Filename | Overview |
|---|---|
| redash/handlers/queries.py | Adds correctly placed validation against the existing 255-character name and 4096-character description limits. |
| tests/handlers/test_queries.py | Adds focused regression coverage for oversized fields on query creation and update. |
Reviews (1): Last reviewed commit: "Return 400 instead of 500 for over-long ..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Description
Fixes #7478.
Creating (or updating) a query with a name longer than 255 characters returned a 500: the handler passed the value straight through to the database, where the insert failed with
psycopg2.errors.StringDataRightTruncation(value too long for type character varying(255)). The same applies todescription(varchar(4096)).This adds a small
require_valid_field_lengths()check inredash/handlers/queries.py, used by bothQueryListResource.post(create) andQueryResource.post(update). It reads the maximum lengths from the model's column definitions (no duplicated magic numbers) and aborts with400and a message likeQuery name must be at most 255 characters long.How is this tested?
New tests in
tests/handlers/test_queries.py:TestQueryListResourcePost::test_rejects_too_long_nameTestQueryListResourcePost::test_rejects_too_long_descriptionTestQueryResourcePost::test_update_query_rejects_too_long_nameBefore the fix these fail with
sqlalchemy.exc.DataError(the 500 from the issue); with the fixpytest tests/handlers/test_queries.pypasses (37 passed).ruff checkandblack --checkare clean.Related Tickets & Documents
#7478
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
N/A (backend only)