From ac898773dc2cd0dd7c2bce5a98370e006c288598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 26 Nov 2024 15:19:56 +0100 Subject: [PATCH 1/2] test: add test with 'roles' table Add a test that verifies that a table with the same name as a system view can be used. --- test/system/test_basics.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/system/test_basics.py b/test/system/test_basics.py index 3357104c..bf5724a2 100644 --- a/test/system/test_basics.py +++ b/test/system/test_basics.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from typing import Optional, List from sqlalchemy import ( text, @@ -21,11 +22,14 @@ String, Index, MetaData, - Boolean, + Boolean, ARRAY, ) +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session from sqlalchemy.testing import eq_ from sqlalchemy.testing.plugin.plugin_base import fixtures +from samples.conftest import connection + class TestBasics(fixtures.TablesTest): @classmethod @@ -74,3 +78,27 @@ def test_reflect(self, connection): dialect_options = index.dialect_options["spanner"] eq_(1, len(dialect_options["storing"])) eq_("alternative_name", dialect_options["storing"][0]) + + def test_table_name_overlapping_with_system_table(self, connection): + class Base(DeclarativeBase): + pass + + class Role(Base): + __tablename__ = "roles" + id: Mapped[int] = mapped_column(Integer, primary_key=True) + name: Mapped[str] = mapped_column(String(100), nullable=True) + type: Mapped[str] = mapped_column(String(100), nullable=True) + description: Mapped[Optional[str]] = mapped_column(String(512)) + + engine = connection.engine + Base.metadata.create_all(engine) + + with Session(engine) as session: + role = Role( + id=1, + name="Test", + type="Test", + description="Test", + ) + session.add(role) + session.commit() From 8134bb4dcf90634e9f93fc722b62ade83160062f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 26 Nov 2024 15:24:21 +0100 Subject: [PATCH 2/2] chore: fix linting --- test/system/test_basics.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/system/test_basics.py b/test/system/test_basics.py index bf5724a2..e9e9d834 100644 --- a/test/system/test_basics.py +++ b/test/system/test_basics.py @@ -11,8 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional, List +from typing import Optional from sqlalchemy import ( text, Table, @@ -22,14 +22,12 @@ String, Index, MetaData, - Boolean, ARRAY, + Boolean, ) from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session from sqlalchemy.testing import eq_ from sqlalchemy.testing.plugin.plugin_base import fixtures -from samples.conftest import connection - class TestBasics(fixtures.TablesTest): @classmethod