Skip to content
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

Fixed #35448 -- Created a custom StreamHandler for DebugSQLTextTestResult #18255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HanaPoulpe
Copy link

Trac ticket number

ticket-35448

Branch description

Test using --debug-sql were formatting the whole logstream instead on only the SQL code within it.

As discussed in the ticket:

  • we want to avoid using regex to reformat only the SQL code.
  • the information about the SQL code is available at the LogRecord level but is lost after formatting

This introduces a specific handler that keeps track of all record to reformat only the SQL code when requested by the --debug-sql flag.
This has the downfall of requiring to keep the records in memory alongside of their output until the end of the test suite instead of only keeping the formatted output.

When the formatted SQL display is required, the handler will reformat run a new formatting round to make the output multi-line (eg: 1 line per attribute + formatted SQL code) to keep the display as close at it was previously.

One issue I did not manage to solve is when the test returns an error instead of a failure, in this case the LogHandler is not created and we don't have the details on the SQL code. When this happens, the previous behavior is maintained.

New output

(0.000) 
INSERT INTO "data_somemodel" ("name")
VALUES ('d') RETURNING "data_somemodel"."id";

args=('d',);

alias=default


(0.000) 
SELECT "data_somemodel"."id",
       "data_somemodel"."name"
FROM "data_somemodel"
WHERE "data_somemodel"."id" > 0
ORDER BY "data_somemodel"."name" ASC
LIMIT 21;

args=(0,);

alias=default

Old output

(0.000)
INSERT INTO "data_somemodel" ("name")
VALUES ('d') RETURNING "data_somemodel"."id";

args=('d',);

ALIAS=DEFAULT (0.000)
SELECT "data_somemodel"."id",
       "data_somemodel"."name"
FROM "data_somemodel"
WHERE "data_somemodel"."id" > 0
ORDER BY "data_somemodel"."name" ASC
LIMIT 21;

args=(0,);

ALIAS=DEFAULT

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • [N/A] I have added or updated relevant docs, including release notes if applicable.
  • [N/A] I have attached screenshots in both light and dark modes for any UI changes.

…tResult` to keep track of the SQL query and reformat the records.
@HanaPoulpe HanaPoulpe force-pushed the test/debug-sql-format-only-query branch from f0b2ee2 to f879952 Compare June 8, 2024 15:28
@HanaPoulpe HanaPoulpe marked this pull request as ready for review June 8, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant