Skip to content

BUG: ensure custom_ucd_coord_meta_mapping context manager performs a (correct) cleanup - #17749

Merged
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:visualization/bug/fix-global-state-pollution-in-context-manager
Feb 17, 2025
Merged

pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:visualization/bug/fix-global-state-pollution-in-context-manager

Conversation

@neutrinoceros

@neutrinoceros neutrinoceros commented Feb 10, 2025 •

Copy link
Copy Markdown
Contributor

Description

This fixes test pollution seen in two tests (partially address #17745).
Follow up to #16347.
Reprod:

pytest astropy/visualization/wcsaxes/tests/test_wcsapi.py astropy/visualization/wcsaxes/tests/test_wcsapi.py --keep-duplicate

There were a couple defects in this context managers:

  • its cleanup stage wasn't performed if an exception was raised during execution
  • there was no attempt to restore overwritten parts of the dictionary that represents the global state

I augmented the affected tests to make them fail on their own if the global state is changed.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@neutrinoceros neutrinoceros changed the title BUG: ensure custom_ucd_coord_meta_mapping context manager performs a (correct) cleanup BUG: ensure custom_ucd_coord_meta_mapping context manager performs a (correct) cleanup Feb 10, 2025
@neutrinoceros
neutrinoceros force-pushed the visualization/bug/fix-global-state-pollution-in-context-manager branch 2 times, most recently from 080bf9d to b864258 Compare February 10, 2025 09:57

def test_custom_coord_type_from_ctype_nested():
from astropy.visualization.wcsaxes.wcsapi import (
CUSTOM_UCD_COORD_META_MAPPING as global_state, # noqa: N811

@neutrinoceros neutrinoceros Feb 10, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

N811 is constant-imported-as-non-constant. I decided to ignore this rule here since CUSTOM_UCD_COORD_META_MAPPING is by no means a constant (hence the bugs and fixes), despite what the case suggests.

Suggested change
CUSTOM_UCD_COORD_META_MAPPING as global_state, # noqa: N811
CUSTOM_UCD_COORD_META_MAPPING as global_state, # noqa: N811

@neutrinoceros
neutrinoceros force-pushed the visualization/bug/fix-global-state-pollution-in-context-manager branch from b864258 to d2bded8 Compare February 10, 2025 10:23
@neutrinoceros
neutrinoceros marked this pull request as ready for review February 10, 2025 11:49

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me but obviously should have review from wcs team.

Comment thread astropy/visualization/wcsaxes/wcsapi.py Resolved
Comment thread astropy/visualization/wcsaxes/wcsapi.py Resolved
@neutrinoceros
neutrinoceros force-pushed the visualization/bug/fix-global-state-pollution-in-context-manager branch from d2bded8 to baec449 Compare February 10, 2025 14:36
Comment thread astropy/visualization/wcsaxes/wcsapi.py Outdated
from .frame import EllipticalFrame, RectangularFrame, RectangularFrame1D
from .transforms import CurvedTransform

if TYPE_CHECKING:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the typing stuff really necessary here to fix the failures?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if you could simplify this patch to just the needed changes so it is easier to backport... 😬

@neutrinoceros neutrinoceros Feb 12, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to prove a point and tried applying the patch as is to v7.0.x and... found that it is indeed only trivial to backport without this part... so, as much as it saddens me, I'll remove it now. Thanks for pointing it out !

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your understanding!

@pllim pllim mentioned this pull request Feb 10, 2025
1 task
@neutrinoceros
neutrinoceros force-pushed the visualization/bug/fix-global-state-pollution-in-context-manager branch from baec449 to 5973dcf Compare February 12, 2025 18:26
@pllim

pllim commented Feb 12, 2025

Copy link
Copy Markdown
Member

@mhvk , this actually touches visualization.wcsaxes more than it does actual wcs . If we don't hear back from @astrofrog , @Cadair , or @larrybradley , does your approval still stand? If so, we can probably just merge it in a week or so regardless.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, I'm fine with my approval being good enough - the actual code changes are logical and good (and I like the test changes too!).

@pllim
pllim merged commit b7c3563 into astropy:main Feb 17, 2025
@pllim

pllim commented Feb 17, 2025

Copy link
Copy Markdown
Member

Merged. Thanks, all!

meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Feb 17, 2025
…` context manager performs a (correct) cleanup
pllim added a commit that referenced this pull request Feb 17, 2025
…749-on-v7.0.x

Backport PR #17749 on branch v7.0.x (BUG: ensure `custom_ucd_coord_meta_mapping` context manager performs a (correct) cleanup)
@neutrinoceros
neutrinoceros deleted the visualization/bug/fix-global-state-pollution-in-context-manager branch February 18, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants