Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling patch with no changes will fail #355

Open
armanddidierjean opened this issue Mar 2, 2024 · 0 comments
Open

Calling patch with no changes will fail #355

armanddidierjean opened this issue Mar 2, 2024 · 0 comments

Comments

@armanddidierjean
Copy link
Member

Subject of the issue

If we call an update crud without providing any change, an error will be thrown.

Proposed solution

    if not any(recommendation.model_dump().values()):
        return

    result = await db.execute(
        update(models_recommendation.Recommendation)
        .where(models_recommendation.Recommendation.id == recommendation_id)
        .values(**recommendation.model_dump(exclude_none=True))
    )
    if result.rowcount == 1:
        await db.commit()
    else:
        await db.rollback()
        raise ValueError

See @julien4215 comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant