Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .check_expression_baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"entries": {
"0e54460ae5900183": 1,
"1aca83c370df2ada": 1,
"2b06a04b4145896b": 1,
"7cfb3ec7a6a501ee": 1,
"8e85b0f3244552f3": 1,
"993d08027423c8a1": 1,
"a806580bef004f80": 1,
"bbb862dfa6d96fe5": 1,
"bf4f8566a803c1c0": 2,
"e636ddd3fb33a58e": 1,
"fad78a2f8206e058": 2
},
"findings": [
{
"found": "getattr(expr, \"or_replace\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"if_not_exists\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"partition_by\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"cluster_by\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"options\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"cascade\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"restrict\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"if_exists\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(expr, \"if_exists\", False)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/materialized_view.py",
"rule": "ED-11.2"
},
{
"found": "getattr(data_type, \"precision\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/types.py",
"rule": "ED-11.2"
},
{
"found": "getattr(data_type, \"scale\", 0)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/types.py",
"rule": "ED-11.2"
},
{
"found": "getattr(data_type, \"length\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/types.py",
"rule": "ED-11.2"
},
{
"found": "getattr(data_type, \"length\", None)",
"path": "src/rhosocial/activerecord/backend/impl/bigquery/mixins/types.py",
"rule": "ED-11.2"
}
],
"format": 1
}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ env:
# This branch pins the core and testsuite feature branches so the error-taxonomy
# and execute-contract changes under review are installed together. Restore the
# release-branch pins once those branches are merged.
CORE_PKG: "rhosocial-activerecord @ git+https://github.com/rhosocial/python-activerecord.git@feature/error-taxonomy"
TESTSUITE_PKG: "rhosocial-activerecord-testsuite @ git+https://github.com/rhosocial/python-activerecord-testsuite.git@feature/error-taxonomy"
CORE_PKG: "rhosocial-activerecord @ git+https://github.com/rhosocial/python-activerecord.git@release/v1.0.0.dev30"
TESTSUITE_PKG: "rhosocial-activerecord-testsuite @ git+https://github.com/rhosocial/python-activerecord-testsuite.git@release/v1.0.0.dev17"

jobs:
test:
Expand Down
8 changes: 3 additions & 5 deletions tests/providers/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
from rhosocial.activerecord.testsuite.feature.basic.fixtures.models import ( # noqa: E402
OrderItem as CompositeOrderItem,
AsyncOrderItem as AsyncCompositeOrderItem,
StoreInventory as StoreInventoryModel,
AsyncStoreInventory as AsyncStoreInventoryModel,
Order as OrderModel,
AsyncOrder as AsyncOrderModel,
MappedOrderItem as MappedOrderItemModel,
Expand Down Expand Up @@ -143,7 +141,7 @@ def _track_backend(backend_instance, collection: List) -> None:
def _set_schema(self, model_class: Type[ActiveRecord], dataset: Optional[str]) -> None:
# Qualify all model SQL with the scenario dataset; without it the
# emulator client would resolve bare table names against nothing.
model_class.__schema_name__ = dataset
model_class.schema_name = classmethod(lambda cls: dataset)

def _table_ddl(self, dataset: Optional[str], table_name: str) -> str:
if fn := TABLE_EXPRESSIONS.get(table_name):
Expand Down Expand Up @@ -209,7 +207,7 @@ def _setup_multiple_models(
model_class.__connection_config__ = first_model.__connection_config__
model_class.__backend_class__ = first_model.__backend_class__
model_class.__backend__ = shared_backend
model_class.__schema_name__ = first_model.__schema_name__
model_class.schema_name = classmethod(lambda cls: first_model.schema_name())
self._track_backend(shared_backend, self._active_backends)
self._initialize_model_schema(model_class, table_name)
self._created_tables.add(table_name)
Expand Down Expand Up @@ -364,7 +362,7 @@ async def _setup_multiple_async_models(
model_class.__connection_config__ = first_model.__connection_config__
model_class.__backend_class__ = first_model.__backend_class__
model_class.__backend__ = shared_backend
model_class.__schema_name__ = first_model.__schema_name__
model_class.schema_name = classmethod(lambda cls: first_model.schema_name())
await self._initialize_async_model_schema(model_class, table_name)
self._created_tables.add(table_name)
result.append(model_class)
Expand Down
8 changes: 4 additions & 4 deletions tests/providers/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

import logging
from typing import Dict, List, Optional, Set, Tuple, Type
from typing import List, Optional, Set, Tuple, Type

from rhosocial.activerecord.model import ActiveRecord, AsyncActiveRecord

Expand Down Expand Up @@ -105,7 +105,7 @@ def _track_backend(backend_instance, collection: List) -> None:
collection.append(backend_instance)

def _set_schema(self, model_class: Type[ActiveRecord], dataset: Optional[str]) -> None:
model_class.__schema_name__ = dataset
model_class.schema_name = classmethod(lambda cls: dataset)


class QuerySyncProvider(QueryProviderBase, IQuerySyncProvider):
Expand Down Expand Up @@ -174,7 +174,7 @@ def _setup_multiple_models(
model_class.__connection_config__ = first_model.__connection_config__
model_class.__backend_class__ = first_model.__backend_class__
model_class.__backend__ = shared_backend
model_class.__schema_name__ = first_model.__schema_name__
model_class.schema_name = classmethod(lambda cls: first_model.schema_name())
self._reset_table(shared_backend, _dataset_of(shared_backend.config), table_name)
result.append(model_class)
return tuple(result)
Expand Down Expand Up @@ -314,7 +314,7 @@ def _configure_async_model(
model_class.__connection_config__ = config
model_class.__backend_class__ = AsyncBigQueryBackend
model_class.__backend__ = backend
model_class.__schema_name__ = _dataset_of(config)
model_class.schema_name = classmethod(lambda cls: _dataset_of(config))
return backend

async def _setup_async_model(
Expand Down
12 changes: 6 additions & 6 deletions tests/providers/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def _configure_with_shared_backend(self, model_class, config, backend_class, bac
model_class.__connection_config__ = config
model_class.__backend_class__ = backend_class
model_class.__backend__ = backend
model_class.__schema_name__ = dataset
model_class.schema_name = classmethod(lambda cls: dataset)

def _setup_employee_department(self, scenario_name):
backend_class, config = get_scenario(scenario_name)
Employee.configure(config, backend_class)
backend = Employee.backend()
self._active_backends.append(backend)
self._configure_with_shared_backend(Department, config, backend_class, backend, _dataset_of(config))
Employee.__schema_name__ = _dataset_of(config)
Employee.schema_name = classmethod(lambda cls: _dataset_of(config))
self._reset_tables(backend, _EMPLOYEE_DEPARTMENT_TABLES)
return Employee, Department

Expand All @@ -142,7 +142,7 @@ def _setup_author_book(self, scenario_name):
backend = Author.backend()
self._active_backends.append(backend)
dataset = _dataset_of(config)
Author.__schema_name__ = dataset
Author.schema_name = classmethod(lambda cls: dataset)
self._configure_with_shared_backend(Book, config, backend_class, backend, dataset)
self._configure_with_shared_backend(Chapter, config, backend_class, backend, dataset)
self._configure_with_shared_backend(Profile, config, backend_class, backend, dataset)
Expand All @@ -156,7 +156,7 @@ def _setup_user_post_comment_sync(self, scenario_name):
backend = User.backend()
self._active_backends.append(backend)
dataset = _dataset_of(config)
User.__schema_name__ = dataset
User.schema_name = classmethod(lambda cls: dataset)
self._configure_with_shared_backend(Post, config, backend_class, backend, dataset)
self._configure_with_shared_backend(Comment, config, backend_class, backend, dataset)
self._reset_tables(backend, _USER_POST_COMMENT_TABLES)
Expand All @@ -169,7 +169,7 @@ def _setup_relation_boundary_sync(self, scenario_name):
backend = BoundaryOwner.backend()
self._active_backends.append(backend)
dataset = _dataset_of(config)
BoundaryOwner.__schema_name__ = dataset
BoundaryOwner.schema_name = classmethod(lambda cls: dataset)
self._configure_with_shared_backend(BoundaryProfile, config, backend_class, backend, dataset)
self._configure_with_shared_backend(BoundaryPost, config, backend_class, backend, dataset)
self._reset_tables(backend, _RELATION_BOUNDARY_TABLES)
Expand Down Expand Up @@ -316,7 +316,7 @@ def _configure_async_model(
model_class.__connection_config__ = config
model_class.__backend_class__ = AsyncBigQueryBackend
model_class.__backend__ = backend
model_class.__schema_name__ = _dataset_of(config)
model_class.schema_name = classmethod(lambda cls: _dataset_of(config))
return backend

async def _setup_employee_department_async(self, scenario_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,17 @@ def create_table_statement_classes(cls):


class DeclarationModel(TableDeclarationOverrides, ActiveRecord):
__table_name__ = "ddl_source_declarations"
__schema_name__ = "analytics"
__primary_key__ = "record_id"
@classmethod
def table_name(cls):
return "ddl_source_declarations"

@classmethod
def schema_name(cls):
return "analytics"

@classmethod
def primary_key(cls):
return "record_id"

id: Annotated[int, UseColumn("record_id")]
value: Annotated[
Expand All @@ -196,9 +204,17 @@ class DeclarationModel(TableDeclarationOverrides, ActiveRecord):


class AsyncDeclarationModel(TableDeclarationOverrides, AsyncActiveRecord):
__table_name__ = "ddl_source_declarations_async"
__schema_name__ = "analytics"
__primary_key__ = "record_id"
@classmethod
def table_name(cls):
return "ddl_source_declarations_async"

@classmethod
def schema_name(cls):
return "analytics"

@classmethod
def primary_key(cls):
return "record_id"

id: Annotated[int, UseColumn("record_id")]
value: Annotated[
Expand All @@ -221,22 +237,31 @@ class AsyncDeclarationModel(TableDeclarationOverrides, AsyncActiveRecord):


class PlainModel(ActiveRecord):
__table_name__ = "ddl_source_plain"
@classmethod
def table_name(cls):
return "ddl_source_plain"

id: int
value: Optional[str] = None


class AsyncPlainModel(AsyncActiveRecord):
__table_name__ = "ddl_source_plain_async"
@classmethod
def table_name(cls):
return "ddl_source_plain_async"

id: int
value: Optional[str] = None


class CompositeModel(TableDeclarationOverrides, ActiveRecord):
__table_name__ = "ddl_source_composite"
__primary_key__ = ("tenant_id", "order_id")
@classmethod
def table_name(cls):
return "ddl_source_composite"

@classmethod
def primary_key(cls):
return ("tenant_id", "order_id")

tenant_ref: Annotated[int, UseColumn("tenant_id")]
order_ref: Annotated[int, UseColumn("order_id")]
Expand All @@ -246,8 +271,13 @@ class CompositeModel(TableDeclarationOverrides, ActiveRecord):


class AsyncCompositeModel(TableDeclarationOverrides, AsyncActiveRecord):
__table_name__ = "ddl_source_composite_async"
__primary_key__ = ("tenant_id", "order_id")
@classmethod
def table_name(cls):
return "ddl_source_composite_async"

@classmethod
def primary_key(cls):
return ("tenant_id", "order_id")

tenant_ref: Annotated[int, UseColumn("tenant_id")]
order_ref: Annotated[int, UseColumn("order_id")]
Expand Down
Loading