Skip to content

prevent unnecessary keyError in add_attribute - #1461

Open
mahdishirvani79 wants to merge 1 commit into
MISP:mainfrom
mahdishirvani79:prevent_unnecessary_keyError_in_add_attribute
Open

prevent unnecessary keyError in add_attribute#1461
mahdishirvani79 wants to merge 1 commit into
MISP:mainfrom
mahdishirvani79:prevent_unnecessary_keyError_in_add_attribute

Conversation

@mahdishirvani79

Copy link
Copy Markdown

When calling add_attribute() with a list of attributes where every attribute is invalid (for example, due to a type mismatch), _check_json_response() returns a dictionary containing only an errors key and no Attribute key.

When pythonify=True, the code assumes the Attribute key is always present and iterates over new_attribute['Attribute'], which raises a KeyError in this case.

This change replaces direct indexing with new_attribute.get('Attribute', []), allowing the method to handle error-only responses gracefully while preserving the existing behaviour for successful responses.

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 this pull request may close these issues.

1 participant