diff --git a/accountant/views/accounts.py b/accountant/views/accounts.py index 32de41c..2e92125 100644 --- a/accountant/views/accounts.py +++ b/accountant/views/accounts.py @@ -148,7 +148,7 @@ class AccountListResource(Resource): data = self.api.payload # A new account MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') # Instantiate account with data. @@ -203,7 +203,7 @@ class AccountResource(Resource): data = self.api.payload # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != account_id: + if data.get('id', default=account_id) != account_id: ns.abort(406, 'Id must not be provided or changed on update.') # Need to get the object to update it. diff --git a/accountant/views/operations.py b/accountant/views/operations.py index cc0cc5f..b21c513 100644 --- a/accountant/views/operations.py +++ b/accountant/views/operations.py @@ -132,7 +132,7 @@ class OperationListResource(Resource): ns.abort(404, 'Account with id %d not found.' % account_id) # A new operation MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') operation = Operation(**data) @@ -181,7 +181,7 @@ class OperationResource(Resource): data = self.api.payload # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != operation_id: + if data.get('id', default=operation_id) != operation_id: ns.abort(406, 'Id must not be provided or changed on update.') # pylint: disable=no-member diff --git a/accountant/views/scheduled_operations.py b/accountant/views/scheduled_operations.py index b73c992..2f48461 100644 --- a/accountant/views/scheduled_operations.py +++ b/accountant/views/scheduled_operations.py @@ -106,7 +106,7 @@ class ScheduledOperationListResource(Resource): ns.abort(404, 'Account with id %d not found.' % account_id) # A new scheduled operation MUST NOT have an id; - if 'id' in data and data['id']: + if data.get('id') is not None: ns.abort(406, 'Id must not be provided on creation.') scheduled_operation = ScheduledOperation(**data) @@ -160,7 +160,7 @@ class ScheduledOperationResource(Resource): so_id = scheduled_operation_id # Check ID consistency. - if 'id' in data and data['id'] and data['id'] != so_id: + if data.get('id', default=so_id) != so_id: ns.abort(406, 'Id must not be provided or changed on update.') scheduled_operation = ScheduledOperation.query().get(so_id)