Skip to content

Commit b1da7af

Browse files
authored
fix: TypeError when initializing SQLAlchemyAsyncQueryRepository (#538)
Corrects a TypeError reported from the init method of `SQLAlchemyAsyncQueryRepository`
1 parent cf01f24 commit b1da7af

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

advanced_alchemy/repository/_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,10 +2295,9 @@ def __init__(
22952295
session: Session managing the unit-of-work for the operation.
22962296
error_messages: A set of error messages to use for operations.
22972297
wrap_exceptions: Whether to wrap exceptions in a SQLAlchemy exception.
2298-
**kwargs: Additional arguments.
2298+
**kwargs: Additional arguments (ignored).
22992299
23002300
"""
2301-
super().__init__(**kwargs)
23022301
self.session = session
23032302
self.error_messages = error_messages
23042303
self.wrap_exceptions = wrap_exceptions

advanced_alchemy/repository/_sync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,10 +2292,9 @@ def __init__(
22922292
session: Session managing the unit-of-work for the operation.
22932293
error_messages: A set of error messages to use for operations.
22942294
wrap_exceptions: Whether to wrap exceptions in a SQLAlchemy exception.
2295-
**kwargs: Additional arguments.
2295+
**kwargs: Additional arguments (ignored).
22962296
22972297
"""
2298-
super().__init__(**kwargs)
22992298
self.session = session
23002299
self.error_messages = error_messages
23012300
self.wrap_exceptions = wrap_exceptions

tests/integration/test_sqlquery_service.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,73 @@ async def test_async_fixture_and_query(async_engine: AsyncEngine, sqlquery_test_
275275
)
276276
assert not is_msgspec_struct_without_field(_msgspec_obj, "state_abbreviation")
277277
assert _get_one_or_none is None
278+
279+
280+
@pytest.mark.xdist_group("sqlquery")
281+
async def test_async_query_repository_instantiation(async_engine: AsyncEngine) -> None:
282+
"""Test that SQLAlchemyAsyncQueryRepository can be instantiated without super().__init__() error."""
283+
from advanced_alchemy.repository import SQLAlchemyAsyncQueryRepository
284+
285+
async with AsyncSession(async_engine) as session:
286+
# Test direct instantiation - this should not raise TypeError
287+
repository = SQLAlchemyAsyncQueryRepository(session=session)
288+
assert repository is not None
289+
assert repository.session == session
290+
assert repository.error_messages is None
291+
assert repository.wrap_exceptions is True
292+
293+
# Test with optional parameters
294+
repository_with_params = SQLAlchemyAsyncQueryRepository(
295+
session=session, error_messages={"not_found": "Custom not found"}, wrap_exceptions=False
296+
)
297+
assert repository_with_params.session == session
298+
assert repository_with_params.error_messages == {"not_found": "Custom not found"}
299+
assert repository_with_params.wrap_exceptions is False
300+
301+
302+
@pytest.mark.xdist_group("sqlquery")
303+
def test_sync_query_repository_instantiation(engine: Engine) -> None:
304+
"""Test that SQLAlchemySyncQueryRepository can be instantiated without super().__init__() error."""
305+
from advanced_alchemy.repository import SQLAlchemySyncQueryRepository
306+
307+
with Session(engine) as session:
308+
# Test direct instantiation - this should not raise TypeError
309+
repository = SQLAlchemySyncQueryRepository(session=session)
310+
assert repository is not None
311+
assert repository.session == session
312+
assert repository.error_messages is None
313+
assert repository.wrap_exceptions is True
314+
315+
# Test with optional parameters
316+
repository_with_params = SQLAlchemySyncQueryRepository(
317+
session=session, error_messages={"not_found": "Custom not found"}, wrap_exceptions=False
318+
)
319+
assert repository_with_params.session == session
320+
assert repository_with_params.error_messages == {"not_found": "Custom not found"}
321+
assert repository_with_params.wrap_exceptions is False
322+
323+
324+
@pytest.mark.xdist_group("sqlquery")
325+
async def test_async_query_service_with_repository_instantiation(async_engine: AsyncEngine) -> None:
326+
"""Test that SQLAlchemyAsyncQueryService using the repository works correctly."""
327+
from advanced_alchemy.service import SQLAlchemyAsyncQueryService
328+
329+
async with AsyncSession(async_engine) as session:
330+
# This should not raise TypeError when creating the repository internally
331+
query_service = SQLAlchemyAsyncQueryService(session=session)
332+
assert query_service is not None
333+
assert query_service.repository is not None
334+
assert query_service.repository.session == session
335+
336+
337+
@pytest.mark.xdist_group("sqlquery")
338+
def test_sync_query_service_with_repository_instantiation(engine: Engine) -> None:
339+
"""Test that SQLAlchemySyncQueryService using the repository works correctly."""
340+
from advanced_alchemy.service import SQLAlchemySyncQueryService
341+
342+
with Session(engine) as session:
343+
# This should not raise TypeError when creating the repository internally
344+
query_service = SQLAlchemySyncQueryService(session=session)
345+
assert query_service is not None
346+
assert query_service.repository is not None
347+
assert query_service.repository.session == session

0 commit comments

Comments
 (0)