update tests for code or if nessesary fix code.
log:
...
.2024-09-18 16:34:19.258 | INFO     | tests.repo.test_base_repo:test_update_or_create_kwargs_override_defaults:641 - Start test_update_or_create_kwargs_override_defaults
2024-09-18 16:34:19.260 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - No instance found matching filters: {'name': 'UpdateOrCreate Item'}
2024-09-18 16:34:19.265 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - Found instance found matching filters: {'name': 'UpdateOrCreate Item'}
.2024-09-18 16:34:19.286 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - Found instance found matching filters: {'name': 'Filter Item'}
2024-09-18 16:34:19.287 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - No instance found matching filters: {'name': 'NonExistent'}
.2024-09-18 16:34:19.308 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - Found instance found matching filters: {'name': 'Item 2', 'status': 'PROCESSING'}
2024-09-18 16:34:19.309 | DEBUG    | app.base.repo.base_repo:get_by_filters:307 - No instance found matching filters: {'name': 'Item 1', 'status': 'PROCESSING'}
.......2024-09-18 16:34:19.469 | ERROR    | app.base.repo.base_repo:_commit_and_refresh:45 - Transaction rolled back. Error: (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class 'asyncpg.exceptions.UniqueViolationError'>: duplicate key value violates unique constraint "test_model_name_key"
DETAIL:  Key (name)=(Duplicate Item) already exists.
[SQL: INSERT INTO test_model (name, status, start_datetime, end_datetime, uuid, created_at, updated_at, deleted_at, enabled) VALUES ($1::VARCHAR, $2::callcampaignstatus, $3::TIMEST
AMP WITH TIME ZONE, $4::TIMESTAMP WITH TIME ZONE, $5::UUID, $6::TIMESTAMP WITH TIME ZONE, $7::TIMESTAMP WITH TIME ZONE, $8::TIMESTAMP WITH TIME ZONE, $9::BOOLEAN) RETURNING test_model.id]
[parameters: ('Duplicate Item', 'EXPECTING_FILES', datetime.datetime(2024, 9, 18, 16, 34, 19, 462095, tzinfo=zoneinfo.ZoneInfo(key='UTC')), datetime.datetime(2024, 9, 19, 16, 34, 19, 462099, tzinfo=zoneinfo.ZoneInfo(key='UTC')), 'deb12395-f1cc-4f84-8338-199fc87724d7', datetime.datetime(2024, 9, 18, 16, 34, 19, 466375, tzinfo=<UTC>), None, None, True)]       
(Background on this error at: https://sqlalche.me/e/20/gkpj)
.2024-09-18 16:34:19.486 | ERROR    | app.base.repo.base_repo:_commit_and_refresh:45 - Transaction rolled back. Error: (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class 'asyncpg.exceptions.NotNullViolationError'>: null value in column "name" of relation "test_model" violates not-null constraint
DETAIL:  Failing row contains (null, EXPECTING_FILES, 2024-09-18 16:34:19.483859+00, 2024-09-19 16:34:19.483866+00, 55, db2f468b-cd67-4df1-9fc4-28a440ebad64, 2024-09-18 16:34:19.48453+00, null, null, t).
[SQL: INSERT INTO test_model (name, status, start_datetime, end_datetime, uuid, created_at, updated_at, deleted_at, enabled) VALUES ($1::VARCHAR, $2::callcampaignstatus, $3::TIMEST
AMP WITH TIME ZONE, $4::TIMESTAMP WITH TIME ZONE, $5::UUID, $6::TIMESTAMP WITH TIME ZONE, $7::TIMESTAMP WITH TIME ZONE, $8::TIMESTAMP WITH TIME ZONE, $9::BOOLEAN) RETURNING test_model.id]
[parameters: (None, 'EXPECTING_FILES', datetime.datetime(2024, 9, 18, 16, 34, 19, 483859, tzinfo=zoneinfo.ZoneInfo(key='UTC')), datetime.datetime(2024, 9, 19, 16, 34, 19, 483866, tzinfo=zoneinfo.ZoneInfo(key='UTC')), 'db2f468b-cd67-4df1-9fc4-28a440ebad64', datetime.datetime(2024, 9, 18, 16, 34, 19, 484530, tzinfo=<UTC>), None, None, True)]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
.......2024-09-18 16:34:19.584 | INFO     | tests.conftest:async_global_setup:64 - Teardown if needed
...


@pytest.mark.asyncio
async def test_update_or_create_kwargs_override_defaults(db, base_repo):
    logger.info("Start test_update_or_create_kwargs_override_defaults")
    test_data = {
        "name": "UpdateOrCreate Item",
        "status": CallCampaignStatus.EXPECTING_FILES.value,
        "start_datetime": datetime.now(ZoneInfo("UTC")),
        "end_datetime": datetime.now(ZoneInfo("UTC")) + timedelta(days=1),
    }

    item, created = await base_repo.update_or_create(
        db,
        name="UpdateOrCreate Item",
        defaults=test_data,
    )
    assert isinstance(item, TestModel)
    assert created is True

    # Update with kwargs that should override defaults
    item2, created2 = await base_repo.update_or_create(
        db,
        name="UpdateOrCreate Item",
        defaults={
            "status": CallCampaignStatus.PROCESSING.value,
            "start_datetime": datetime.now(ZoneInfo("UTC")),
            "end_datetime": datetime.now(ZoneInfo("UTC")) + timedelta(days=1),
        },
        status=CallCampaignStatus.COMPLETE.value,  # This should override the default
    )
    assert isinstance(item2, TestModel)
    assert created2 is False
    assert item2.id == item.id
    assert (
        item2.status.value == CallCampaignStatus.COMPLETE.value
    )  # Kwargs status should be used

code:
class BaseRepo(Generic[T,]):
    def __init__(self, model: Type[T]):
        self.model = model
...
    async def soft_delete(self, db: AsyncSession, id: int) -> T | None:
        return await self._execute_update(
            db,
            id,
            {"deleted_at": get_current_datetime(), "enabled": False},
        )

    async def update_or_create(
        self,
        db: AsyncSession,
        defaults: dict[str, Any] | None = None,
        **kwargs,
    ) -> Tuple[T, bool]:
        # Use only the unique criteria for filtering in get_by_filters
        unique_criteria = {
            k: v
            for k, v in kwargs.items()
            if k in self.model.__table__.primary_key.columns
            or self.model.__table__.columns[k].unique
        }
        instance = await self.get_by_filters(db, **unique_criteria)
        if instance:
            await self._update_instance(db, instance, defaults, kwargs)
            return instance, False
        create_data = {**defaults, **kwargs} if defaults else kwargs
        new_instance = await self.create(db, create_data)
        return new_instance, True
		
    async def get_by_filters(self, db: AsyncSession, **kwargs) -> T | None:
        stmt = select(self.model).where(self.model.enabled.is_(True))
        for key, value in kwargs.items():
            stmt = stmt.filter(
                getattr(self.model, key)
                == (value.value if isinstance(value, Enum) else value),
            )
        instance = await self._execute_query(db, stmt)
        logger.debug(
            f"{'Found' if instance else 'No'} instance found matching filters: {kwargs}",
        )
        return instance
		
    async def _update_instance(
        self,
        db: AsyncSession,
        instance: T,
        defaults: dict[str, Any] | None,
        kwargs: dict,
    ):
        update_data = {**defaults, **kwargs} if defaults else kwargs
        for key, value in update_data.items():
            if hasattr(instance, key):
                setattr(instance, key, value)
        await self._commit_and_refresh(db, instance)
		
    async def _commit_and_refresh(self, db: AsyncSession, instance: T):
        try:
            await db.commit()
            await db.refresh(instance)
        except Exception as e:
            await db.rollback()
            logger.error(f"Transaction rolled back. Error: {e}", exc_info=True)
            raise