Skip to content

EC2: match all security groups when filtering describe_instances - #10145

Open
Sanjays2402 wants to merge 1 commit into
getmoto:masterfrom
Sanjays2402:fix/describe-instances-secondary-security-group-10114
Open

EC2: match all security groups when filtering describe_instances#10145
Sanjays2402 wants to merge 1 commit into
getmoto:masterfrom
Sanjays2402:fix/describe-instances-secondary-security-group-10114

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #10114

describe_instances filtered by group-id, instance.group-id or instance.group-name only matched an instance's first security group, so an instance in several groups was wrongly excluded when filtered by any of the others.

get_object_value() returned as soon as the first list element produced a value, so for a list-valued attribute like security_groups only that element's value reached instance_value_in_filter_values(). It now collects the value of every element and returns the full list (or None when empty), which the filter comparison already handles via its list branch.

test_get_instances_filtering_by_secondary_instance_group covers the three affected filters plus the first group; it fails on master and passes with the fix.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

describe_instances filtered by group-id, instance.group-id or
instance.group-name only matched an instance's first security group, so an
instance belonging to several groups was wrongly excluded when filtered by
any of the others.

get_object_value() returned as soon as the first list element produced a
value, so for a list-valued attribute such as security_groups only that
element's value reached instance_value_in_filter_values(). It now collects
the value of every element and returns the full list (or None when empty),
which the filter comparison already handles via its list branch.

Adds test_get_instances_filtering_by_secondary_instance_group covering the
three affected filters plus the first group, which fails without the fix.

Closes getmoto#10114
@ApogeeAC

Copy link
Copy Markdown
Contributor

Duplicates #10115

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.

describe_instances group-id filter only matches an instance's first security group

2 participants