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

chore: Add support for named schema #858

Merged
merged 12 commits into from
Mar 25, 2024
Merged

chore: Add support for named schema #858

merged 12 commits into from
Mar 25, 2024

Conversation

ankiaga
Copy link
Contributor

@ankiaga ankiaga commented Feb 26, 2024

No description provided.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-django API. label Feb 26, 2024
@ankiaga ankiaga marked this pull request as draft February 26, 2024 16:47
@ankiaga ankiaga marked this pull request as ready for review March 11, 2024 04:25
@@ -38,7 +38,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
FROM
information_schema.tables AS t
WHERE
t.table_catalog = '' and t.table_schema = ''
t.table_catalog = '' and t.table_schema = '{schema_name}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the if USE_EMULATOR statement still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as the mentioned bug is closed and support has been added to emulator

results = cursor.run_sql_in_snapshot(self.LIST_TABLE_SQL)
schema_name = self._get_schema_name(cursor)
results = cursor.run_sql_in_snapshot(
self.LIST_TABLE_SQL.format(schema_name=schema_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's not introduced by this PR, but if I understand it correctly, all of these methods generate a SQL statement with a literal in the string, instead of using a query parameter. That means that they are all potentially susceptible to SQL injection. Can we fix that for the queries that we are working on in this PR, and then do a follow-up PR for all other queries? (This should have a high priority)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

table=quoted_table_name
)
WHERE TABLE_NAME=@table AND TABLE_SCHEMA=@schema_name""",
params={"table": quoted_table_name, "schema_name": schema_name},
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not use a quoted table name when it is used as a query parameter. Also; as there is no test failing due to this, I think it means that this method is also not covered by any tests. Would you mind adding a test for this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as discussed

table=quoted_table_name
)
TABLE_NAME=@table AND TABLE_SCHEMA=@schema_name""",
params={"table": quoted_table_name, "schema_name": schema_name},
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also: The table name should not be quoted when used as a parameter. Can we have a test for this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as discussed

table=quoted_table_name
)
""",
params={"table": quoted_table_name, "schema_name": schema_name},
Copy link
Contributor

Choose a reason for hiding this comment

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

Same regarding quoted table name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as discussed

tc.TABLE_NAME=@table AND tc.TABLE_SCHEMA=@schema_name
""",
params={
"table": self.connection.ops.quote_name(table_name),
Copy link
Contributor

Choose a reason for hiding this comment

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

here also: table name should not be quoted, and the lack of a test failure to me seems like a lack of test coverage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as discussed

Copy link
Contributor

@olavloite olavloite left a comment

Choose a reason for hiding this comment

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

LGTM, except for one small nit on a missing clause in a JOIN condition.

django_spanner/introspection.py Outdated Show resolved Hide resolved
@ankiaga ankiaga enabled auto-merge (squash) March 25, 2024 09:09
@ankiaga ankiaga merged commit b648004 into main Mar 25, 2024
30 checks passed
@ankiaga ankiaga deleted the named_schema branch March 25, 2024 09:53
@ankiaga ankiaga added the release-please:force-run To run release-please label Apr 17, 2024
@release-please release-please bot removed the release-please:force-run To run release-please label Apr 17, 2024
This was referenced Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner-django API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants