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
1 change: 1 addition & 0 deletions changelog.d/32.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Breaking:** the fixtures declare models by overriding accessors, following rhosocial-activerecord#140. `__table_name__`, `__primary_key__`, `__pk_auto_generated__` and the locator dunders are no longer read by the core release, so every fixture, provider model and embedded model source now overrides `table_name()`, `primary_key()`, `pk_auto_generated()` or the matching locator method instead; the composite-key contract tests assert `pk_auto_generated()` rather than the removed attribute. 534 declarations across 55 files. A backend that provides models of its own must follow the same shape: a model with no `table_name()` override fails with `NotImplementedError` at the first read.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@


class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: Optional[int] = None
Expand All @@ -23,7 +26,10 @@ class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):


class AsyncBenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, AsyncActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: Optional[int] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@


class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand All @@ -23,7 +26,10 @@ class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):


class AsyncBenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, AsyncActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@


class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand All @@ -23,7 +26,10 @@ class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):


class AsyncBenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, AsyncActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@


class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand All @@ -23,7 +26,10 @@ class BenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, ActiveRecord):


class AsyncBenchmarkUser(IntegerPKMixin, DefaultTimestampMixin, AsyncActiveRecord):
__table_name__ = "benchmark_users"
@classmethod
def table_name(cls):
return "benchmark_users"

c: ClassVar[FieldProxy] = FieldProxy()

id: int | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_primary_key_single(self, order_class):

def test_pk_auto_generated(self, order_item_class):
"""Composite keys should not be auto-generated."""
assert order_item_class.__pk_auto_generated__ is False, \
assert order_item_class.pk_auto_generated() is False, \
"Expected composite key to not be auto-generated"


Expand Down Expand Up @@ -273,7 +273,7 @@ def test_meta_primary_key_field(self, mapped_order_item_class):

def test_meta_pk_auto_generated(self, mapped_order_item_class):
"""Mapped composite keys should not be auto-generated."""
assert mapped_order_item_class.__pk_auto_generated__ is False, \
assert mapped_order_item_class.pk_auto_generated() is False, \
"Expected the key to not be auto-generated"

def test_insert_and_is_new_record(self, mapped_order_item_class):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def test_primary_key_single(self, async_order_class):

async def test_pk_auto_generated(self, async_order_item_class):
"""Composite keys should not be auto-generated."""
assert async_order_item_class.__pk_auto_generated__ is False, \
assert async_order_item_class.pk_auto_generated() is False, \
"Expected composite key to not be auto-generated"

class TestAsyncCompositePKInsert:
Expand Down Expand Up @@ -271,7 +271,7 @@ async def test_meta_primary_key_field(self, async_mapped_order_item_class):

async def test_meta_pk_auto_generated(self, async_mapped_order_item_class):
"""Mapped composite keys should not be auto-generated."""
assert async_mapped_order_item_class.__pk_auto_generated__ is False, \
assert async_mapped_order_item_class.pk_auto_generated() is False, \
"Expected the key to not be auto-generated"

async def test_insert_and_is_new_record(self, async_mapped_order_item_class):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ def test_use_column_conflict_raises(self):
"""UseColumn on derived field must not duplicate a regular field's column name."""
with pytest.raises(TypeError, match="conflicts with a regular field's column name"):
class ConflictModel(ActiveRecord):
__table_name__ = "conflict"
@classmethod
def table_name(cls):
return "conflict"

id: Optional[int] = None
discount_rate: Annotated[float, UseColumn("disc")]
discounted: ClassVar[Annotated[float, DerivedField(
Expand All @@ -403,7 +406,10 @@ class ConflictModel(ActiveRecord):
def test_use_column_no_conflict_different_names(self):
"""Different column names should not conflict."""
class NoConflict(ActiveRecord):
__table_name__ = "no_conflict"
@classmethod
def table_name(cls):
return "no_conflict"

id: Optional[int] = None
discount_rate: Annotated[float, UseColumn("rate")]
discounted: ClassVar[Annotated[float, DerivedField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ async def test_use_column_conflict_raises(self):
"""UseColumn on derived field must not duplicate a regular field's column name."""
with pytest.raises(TypeError, match="conflicts with a regular field's column name"):
class ConflictModel(ActiveRecord):
__table_name__ = "conflict"
@classmethod
def table_name(cls):
return "conflict"

id: Optional[int] = None
discount_rate: Annotated[float, UseColumn("disc")]
discounted: ClassVar[Annotated[float, DerivedField(
Expand All @@ -403,7 +406,10 @@ class ConflictModel(ActiveRecord):
async def test_use_column_no_conflict_different_names(self):
"""Different column names should not conflict."""
class NoConflict(ActiveRecord):
__table_name__ = "no_conflict"
@classmethod
def table_name(cls):
return "no_conflict"

id: Optional[int] = None
discount_rate: Annotated[float, UseColumn("rate")]
discounted: ClassVar[Annotated[float, DerivedField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def test_multiple_use_column_raises_error(self):
"""Verify that using multiple UseColumn annotations raises an error."""
with pytest.raises(TypeError) as excinfo:
class InvalidModel(ActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

# This field has two UseColumn annotations, which is invalid.
name: Annotated[str, UseColumn("col1"), UseColumn("col2")]

Expand All @@ -218,7 +221,10 @@ def _do_from_database(self, value, **kwargs): return value

with pytest.raises(TypeError) as excinfo:
class InvalidModel(ActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

# This field has two UseAdapter annotations, which is invalid.
data: Annotated[
str,
Expand All @@ -233,7 +239,10 @@ def test_use_column_with_invalid_type_raises_error(self):
"""Verify that UseColumn expects a string argument."""
with pytest.raises(TypeError) as excinfo:
class InvalidModel(ActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

# UseColumn is given an integer, but it expects a string.
name: Annotated[str, UseColumn(123)]

Expand All @@ -247,7 +256,10 @@ class NotAnAdapter:

with pytest.raises(TypeError) as excinfo:
class InvalidModel(ActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

# UseAdapter is given an object that is not a BaseSQLTypeAdapter.
data: Annotated[str, UseAdapter(NotAnAdapter(), str)]

Expand All @@ -258,7 +270,9 @@ def test_duplicate_column_name_raises_error(self):
"""Verify that two fields mapping to the same column raises an error."""
with pytest.raises(ValueError) as excinfo:
class InvalidModelWithDuplicates(ActiveRecord):
__table_name__ = "invalid_duplicates"
@classmethod
def table_name(cls):
return "invalid_duplicates"

field_a: Annotated[str, UseColumn("shared_column")]
field_b: Annotated[int, UseColumn("shared_column")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ async def test_multiple_use_column_raises_error(self):

with pytest.raises(TypeError) as excinfo:
class AsyncInvalidModel(AsyncActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

name: Annotated[str, UseColumn("col1"), UseColumn("col2")]

assert "A field can have at most one UseColumn specified" in str(excinfo.value), \
Expand All @@ -220,7 +223,10 @@ def _do_from_database(self, value, **kwargs): return value

with pytest.raises(TypeError) as excinfo:
class AsyncInvalidModel(AsyncActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

data: Annotated[
str,
UseAdapter(DummyAdapter(), str),
Expand All @@ -236,7 +242,10 @@ async def test_use_column_with_invalid_type_raises_error(self):

with pytest.raises(TypeError) as excinfo:
class AsyncInvalidModel(AsyncActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

name: Annotated[str, UseColumn(123)]

assert "Invalid type for column_name. Expected str, but received type int." in str(excinfo.value), \
Expand All @@ -250,7 +259,10 @@ class NotAnAdapter:

with pytest.raises(TypeError) as excinfo:
class AsyncInvalidModel(AsyncActiveRecord):
__table_name__ = "invalid"
@classmethod
def table_name(cls):
return "invalid"

data: Annotated[str, UseAdapter(NotAnAdapter(), str)]

assert "Invalid type for adapter. Expected an instance of SQLTypeAdapter, but received type NotAnAdapter." in str(excinfo.value), \
Expand All @@ -262,7 +274,9 @@ async def test_duplicate_column_name_raises_error(self):

with pytest.raises(ValueError) as excinfo:
class AsyncInvalidModelWithDuplicates(AsyncActiveRecord):
__table_name__ = "invalid_duplicates"
@classmethod
def table_name(cls):
return "invalid_duplicates"

field_a: Annotated[str, UseColumn("shared_column")]
field_b: Annotated[int, UseColumn("shared_column")]
Expand Down
Loading
Loading