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

Support conditions= for save and put operations #85

Open
ricky-sb opened this issue Nov 15, 2019 · 1 comment
Open

Support conditions= for save and put operations #85

ricky-sb opened this issue Nov 15, 2019 · 1 comment
Assignees

Comments

@ricky-sb
Copy link

Class looks like:

from dynamorm import DynaModel
from marshmallow.fields import String

class Device(DynaModel):
    class Table:
        name = 'Device'
        hash_key = 'device_id'
        read = 1
        write = 1

    class Schema:
        device_id = String(required=True)

When I do:

device = Device(device_id='test')
device.save(conditions=dict(device_id__ne='BAD_DEVICE_ID'))

I get this traceback.

Traceback (most recent call last):
  File "~/example.py", line 71, in <module>
    device.save(conditions=dict(device_id__ne='BAD_DEVICE_ID'))
  File "~/venv/lib/site-packages/dynamorm/model.py", line 470, in save
    resp = self.Table.put(as_dict, **kwargs)
  File "~/venv/lib/site-packages/dynamorm/table.py", line 566, in put
    return self.table.put_item(Item=remove_nones(item), **kwargs)
  File "~/venv/lib/site-packages/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "~/venv/lib/site-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "~/venv/lib/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "~/venv/lib/site-packages/botocore/client.py", line 634, in _make_api_call
    api_params, operation_model, context=request_context)
  File "~/venv/lib/site-packages/botocore/client.py", line 682, in _convert_to_request_dict
    api_params, operation_model)
  File "~/venv/lib/site-packages/botocore/validate.py", line 297, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "conditions", must be one of: TableName, Item, Expected, ReturnValues, ReturnConsumedCapacity, ReturnItemCollectionMetrics, ConditionalOperator, ConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues

It does however, work with update:

device = Device(device_id='test')
device.save(conditions=dict(device_id__ne='BAD_DEVICE_ID'))
@ricky-sb
Copy link
Author

After playing with this library some more, I realize the appropriate method to use would be put, however, put doesn't support the conditions kwarg. We have to manually construct a ConditionExpression which gets passed to boto3.

@borgstrom borgstrom changed the title Using conditions= on save results in an error Support conditions= for save and put operations Feb 6, 2020
@borgstrom borgstrom self-assigned this Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants