这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@omriyoffe-panw
Copy link
Contributor

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

New/Edited policies (Delete if not relevant)

Description

Include a description of what makes it a violation and any relevant external links.

Fix

How does someone fix the issue in code and/or in runtime?

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

resource_type_dict = entity.get(resource_type, {})
entity_id = resource_type_dict.get(resource_name, resource_type_dict).get(TF_PLAN_RESOURCE_ADDRESS)
resource_dict = resource_type_dict.get(resource_name, resource_type_dict)
entity_id: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know you could declate it like that 😅

resource_type_dict = entity.get(resource_type, {})
entity_id = resource_type_dict.get(resource_name, resource_type_dict).get(TF_PLAN_RESOURCE_ADDRESS)
resource_dict = resource_type_dict.get(resource_name, resource_type_dict)
if isinstance(resource_dict, dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like that's the same code twice so extract it to a function :)
also - can you add a test for the tf plan which needed that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

else:
entity_id = resource_type_dict.get(TF_PLAN_RESOURCE_ADDRESS)
if not entity_id:
raise Exception(f'Failed get_entity_id: {resource_name} does not have {TF_PLAN_RESOURCE_ADDRESS}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to crash here? It appears this changes the old behavior which theoretically allowed None values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can allow None values but it can lead to unexpected behavior. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue with throwing an exception here is that we fail the entire definitions context building, not just for this entity. If you do decide to throw an exception here, perhaps you can catch it on the outside (log warning) and continue to the next block ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 130 to 137
if not isinstance(resource_definition, dict):
entity_context['start_line'] = resource_type_dict['start_line'][0]
entity_context['end_line'] = resource_type_dict['end_line'][0]
entity_context["code_lines"] = definitions_raw[full_file_path][
entity_context["start_line"]: entity_context["end_line"]
]
entity_context['address'] = resource_type_dict[TF_PLAN_RESOURCE_ADDRESS]
return entity_context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this logic is identical to the one we're running in the "elif" clause, can you extract that into a function and use it from both clauses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@omriyoffe-panw omriyoffe-panw merged commit 8ab4992 into main May 26, 2025
43 of 44 checks passed
@omriyoffe-panw omriyoffe-panw deleted the fix-tfplan-bool branch May 26, 2025 08:44
Saarett pushed a commit that referenced this pull request May 26, 2025
…ject in tfplan scan (#7180)

* add a check to avoid doing get on a none dict object
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.

5 participants