Merge pull request #507 from pcraciunoiu/feature/dynamodb-update-del-missing
Delete missing attribute results in KeyError.
This commit is contained in:
		
						commit
						066b6bf732
					
				@ -125,6 +125,7 @@ class Item(object):
 | 
				
			|||||||
        for attribute_name, update_action in attribute_updates.items():
 | 
					        for attribute_name, update_action in attribute_updates.items():
 | 
				
			||||||
            action = update_action['Action']
 | 
					            action = update_action['Action']
 | 
				
			||||||
            if action == 'DELETE' and not 'Value' in update_action:
 | 
					            if action == 'DELETE' and not 'Value' in update_action:
 | 
				
			||||||
 | 
					                if attribute_name in self.attrs:
 | 
				
			||||||
                    del self.attrs[attribute_name]
 | 
					                    del self.attrs[attribute_name]
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
            new_value = list(update_action['Value'].values())[0]
 | 
					            new_value = list(update_action['Value'].values())[0]
 | 
				
			||||||
@ -137,6 +138,7 @@ class Item(object):
 | 
				
			|||||||
                elif update_action['Value'].keys() == ['N']:
 | 
					                elif update_action['Value'].keys() == ['N']:
 | 
				
			||||||
                    self.attrs[attribute_name] = DynamoType({"N": new_value})
 | 
					                    self.attrs[attribute_name] = DynamoType({"N": new_value})
 | 
				
			||||||
                elif update_action['Value'].keys() == ['NULL']:
 | 
					                elif update_action['Value'].keys() == ['NULL']:
 | 
				
			||||||
 | 
					                    if attribute_name in self.attrs:
 | 
				
			||||||
                        del self.attrs[attribute_name]
 | 
					                        del self.attrs[attribute_name]
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    self.attrs[attribute_name] = DynamoType({"S": new_value})
 | 
					                    self.attrs[attribute_name] = DynamoType({"S": new_value})
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user