Skip to content

fix: key inherited metadata dependency cache per class - #1466

Closed
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/inherited-metadata-dependencies-cache
Closed

fix: key inherited metadata dependency cache per class#1466
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/inherited-metadata-dependencies-cache

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #1459

Summary

MetadataDependent.get_inherited_dependencies() memoized into a plain class attribute and read it back with ordinary attribute lookup. That lookup walks the MRO, so resolving a bare CSTTransformer/CSTVisitor cached an empty frozenset onto the base class, and every subclass that had not yet computed its own cache inherited it — raising METADATA_DEPENDENCIES KeyErrors even though the subclass declares the provider correctly. Reading the cache from cls.__dict__ instead means each class only ever sees its own memoized value.

Test Plan

Added test_bare_visitor_does_not_poison_subclass_dependencies to libcst/metadata/tests/test_metadata_provider.py, which resolves a bare CSTTransformer first and then asserts the subclass still reports its declared dependency. It fails on the unpatched source (frozenset() != {ProviderA}) and passes with the fix; libcst/metadata/tests/, test_visitor.py and test_batched_visitor.py are green (178 passed, only the pre-existing pyre-binary errors in test_type_inference_provider.py).

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

MetadataDependent.get_inherited_dependencies() memoized into a plain
class attribute and read it back with ordinary attribute lookup. That
lookup walks the MRO, so resolving a bare CSTTransformer/CSTVisitor
cached an empty frozenset onto the base class, and every subclass that
had not yet computed its own cache inherited that empty set - raising
METADATA_DEPENDENCIES KeyErrors despite declaring the provider.

Read the cache from cls.__dict__ instead, so each class only ever sees
its own memoized value.

Adds a regression test that resolves a bare CSTTransformer first and
then asserts the subclass still reports its declared dependency.
@meta-cla

meta-cla Bot commented Jul 31, 2026

Copy link
Copy Markdown

Hi @Sanjays2402!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 31, 2026
@meta-cla

meta-cla Bot commented Jul 31, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@Sanjays2402

Copy link
Copy Markdown
Author

Superseded by #1468, which fixes the same issue (#1459) with a tighter diff. Closing this one to avoid duplicate review effort — sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare CSTTransformer metadata pass poisons the inherited-dependency cache for all later subclasses

1 participant