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

[cloudtest] Use correct union types for sql execute statements #21423

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

rjobanp
Copy link
Contributor

@rjobanp rjobanp commented Aug 28, 2023

Motivation

This swaps the LiteralString type annotation to the Query type union defined by psycopg so I can use the psycopg sql.SQL type in a DDL statement where I can't use a LiteralString. See https://www.psycopg.org/psycopg3/docs/advanced/typing.html#checking-literal-strings-in-queries for details

I also switched the Sequence[Any] annotations to use the psycopg Params union-type to future-proof that.

sql_query and sql_execute still annotate their query parameter as str, which is actually incorrect with the move to psycopg 3.. I can update those too but I was wondering if there was a reason to leave them as-is. LMK your thoughts.

Tips for reviewer

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • This PR includes the following user-facing behavior changes:

@nrainer-materialize
Copy link
Contributor

sql_query and sql_execute still annotate their query parameter as str, which is actually incorrect with the move to psycopg 3.. I can update those too but I was wondering if there was a reason to leave them as-is. LMK your thoughts.

Yes, I think we should update them too. I think the .encode("utf8") did the trick so far but no reason to keep that.

Copy link
Contributor

@nrainer-materialize nrainer-materialize left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@necaris
Copy link
Contributor

necaris commented Aug 28, 2023

Yes, I think we should update them too. I think the .encode("utf8") did the trick so far but no reason to keep that.

Right -- encoding them as utf-8 marks it as bytes so it's part of the union type, which is... OK but not amazing.

@rjobanp
Copy link
Contributor Author

rjobanp commented Aug 28, 2023

Great thanks for the input - I've updated all the methods now.

@rjobanp rjobanp merged commit d6845d2 into main Aug 28, 2023
@rjobanp rjobanp deleted the roshan/sql-ddl-typing branch August 28, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants