Upstream 16522 - Refactor formatted raw SQL in unified_jobs result_stdout_raw_handle#587
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors UnifiedJob.result_stdout_raw_handle() to avoid building PostgreSQL COPY ... TO STDOUT SQL via f-strings, replacing interpolated raw SQL with psycopg.sql composables for safer identifier/literal handling while preserving the streaming stdout behavior.
Changes:
- Replaced formatted
COPYSQL construction inresult_stdout_raw_handle()withpsycopg.sql.SQL/Identifier/Literalcomposables. - Updated the SQLite
cursor.copy()functional-test mock to no longer depend on parsing a SQL string.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
awx/main/models/unified_jobs.py |
Builds the COPY (SELECT ...) TO STDOUT statement using psycopg.sql composables instead of f-strings. |
awx/main/tests/functional/conftest.py |
Adjusts the SQLite copy() mock used by stdout-related functional tests to align with the new query construction approach. |
TheWitness
approved these changes
Jul 17, 2026
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.
Upstream Summary
Refactors
UnifiedJob.result_stdout_raw_handle()inawx/main/models/unified_jobs.pyto stop building PostgreSQLCOPYSQL with f-strings.The event-based stdout path previously interpolated table names, column names,
job_created, and job ID directly into a query string (# nosql), which internal security scans flag as formatted raw SQL.This change replaces that with
psycopg.sqlcomposables:sql.Identifier()for table and column namessql.Literal()forjob_createdand the parent FK valueValues are embedded via
sql.Literal()rather than%splaceholders with a separateparamslist, because Django’scursor.copy()only forwards the SQL statement to psycopg and does not pass bind parameters.Behavior is unchanged: the method still streams stdout from job event tables via
COPY ... TO STDOUT, ordered bystart_line, with the same partitioned vs_unpartitioned_table selection and max-bytes checks. Django ORM is intentionally not used here to avoid loading large stdout blobs into memory.The functional test
sqlite_copymock inawx/main/tests/functional/conftest.pywas updated to load stdout from event tables directly instead of parsing SQL strings.Related: AAP-77740 (discovered during AAP-76181)
Issue type
Bug, Docs Fix or other nominal change
Component
Other
Before