Skip to content

Use param in context copy instead of added function #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2022

Conversation

markkuhn
Copy link
Contributor

Issue #, if available: N/A

Description of changes:
This is a small change related to this comment on a PR in the node lib: awslabs/aws-embedded-metrics-node#136 (comment)

To keep all emf libraries consistent I have added that change to this library.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@markkuhn markkuhn self-assigned this Sep 15, 2022
@markkuhn markkuhn added the chore Tasks such as style improvements or refactoring label Sep 15, 2022
@markkuhn markkuhn merged commit a80d047 into awslabs:master Sep 16, 2022
@markkuhn markkuhn deleted the context-copy-fix branch September 16, 2022 04:27
@hussam789
Copy link

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use deepcopy for dimensions

The current implementation directly assigns self.dimensions to new_dimensions
when preserve_dimensions is True, which creates a reference instead of a deep
copy. This can lead to unexpected behavior if the original dimensions are
modified after copying.

aws_embedded_metrics/logger/metrics_context.py [164]

-new_dimensions: List[Dict] = [] if not preserve_dimensions else self.dimensions
+new_dimensions: List[Dict] = [] if not preserve_dimensions else copy.deepcopy(self.dimensions)
  • Apply this suggestion
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a potential bug related to aliasing by referencing self.dimensions directly when preserve_dimensions is True, and the use of copy.deepcopy would ensure that subsequent modifications do not affect the copied context. However, it assumes that importing the copy module is handled elsewhere.

Medium
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Tasks such as style improvements or refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants