Skip to content

Commit d843c47

Browse files
committed
chore: update test to make sure potentially lazy attributes are not accessed
1 parent 725e26a commit d843c47

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/unit/test_repository.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import decimal
77
from collections.abc import AsyncGenerator, Collection, Generator
88
from typing import TYPE_CHECKING, Any, Union, cast
9-
from unittest.mock import AsyncMock, MagicMock
9+
from unittest.mock import AsyncMock, MagicMock, PropertyMock
1010
from uuid import uuid4
1111

1212
import pytest
1313
from msgspec import Struct
1414
from pydantic import BaseModel
1515
from pytest_lazy_fixtures import lf
1616
from sqlalchemy import Integer, String
17-
from sqlalchemy.exc import SQLAlchemyError
17+
from sqlalchemy.exc import InvalidRequestError, SQLAlchemyError
1818
from sqlalchemy.ext.asyncio import AsyncSession
1919
from sqlalchemy.orm import InstrumentedAttribute, Mapped, Session, mapped_column
2020
from sqlalchemy.types import TypeEngine
@@ -1509,8 +1509,8 @@ async def test_update_skips_raise_lazy_relationships(
15091509
mock_mapper.mapper.columns = []
15101510
mock_mapper.mapper.relationships = [mock_relationship]
15111511

1512-
# Mock the data object to have the raise relationship attribute
1513-
mock_instance.items = MagicMock()
1512+
# Mock the data object to raise an error when accessing the relationship
1513+
type(mock_instance).items = PropertyMock(side_effect=InvalidRequestError)
15141514

15151515
mocker.patch.object(mock_repo, "get_id_attribute_value", return_value=id_)
15161516
mocker.patch.object(mock_repo, "get", return_value=existing_instance)

0 commit comments

Comments
 (0)