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

why can't we catch/suppress ConditionalCheckFailedException? #1076

Open
koreno opened this issue Sep 24, 2022 · 3 comments · May be fixed by #1202
Open

why can't we catch/suppress ConditionalCheckFailedException? #1076

koreno opened this issue Sep 24, 2022 · 3 comments · May be fixed by #1202

Comments

@koreno
Copy link

koreno commented Sep 24, 2022

It seems quite unpythonic to force users to write such constructs when dealing with the oh-so-useful conditional operations in DynamoDM:

try:
    thread_item.save(Thread.forum_name.exists())
except PutError as e:
    if isinstance(e.cause, ClientError):
        code = e.cause.response['Error'].get('Code')
        print(code == "ConditionalCheckFailedException")

PynamoDB already issues it own exceptions - why not perform this if and raise a ConditionalCheckFailed? why perpetuate the bad API for boto3 (in this regard) into this otherwise very pythonic library?

Make this work:

try:
    thread_item.save(Thread.forum_name.exists())
except ConditionalCheckFailed:
    pass
@ikonst
Copy link
Contributor

ikonst commented Sep 26, 2022

The only counter-point I can offer is that, unless we break backward compatibility, we'd need to have:

  • UpdateConditionalCheckFailedError extending UpdateError
  • PutConditionalCheckFailedError extending PutError
  • DeleteConditionalCheckFailedError extending DeleteError

BTW, to make it a bit shorter right now, you can opt to use the PynamoDBException.cause_response_code property.

@koreno
Copy link
Author

koreno commented Oct 25, 2023

What do you say? can this be implemented?
I'm still suprised that this is the way to handle something that is so common...
Isn't this supposed to be the value of a pythonic, OO wrapper code to DynamoDB?

@koreno koreno linked a pull request Oct 25, 2023 that will close this issue
@koreno
Copy link
Author

koreno commented Dec 5, 2023

I've submitted this PR - #1202
Would you like to consider it? is there something I should do in order to contribute code properly?

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

Successfully merging a pull request may close this issue.

2 participants