Skip to content

[dynamo] Validate getattr arguments before dispatch - #196526

Closed
lalit10 wants to merge 1 commit into
pytorch:mainfrom
lalit10:fix-dynamo-getattr-arity
Closed

lalit10 wants to merge 1 commit into
pytorch:mainfrom
lalit10:fix-dynamo-getattr-arity

Conversation

@lalit10

@lalit10 lalit10 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #195901.

GetAttrBuiltinVariable accessed positional arguments before validating getattr() calls. Too few arguments could raise an internal IndexError, excess arguments could be silently ignored, and keyword arguments were not rejected before dispatch. Non-string attribute names could also surface as internal Dynamo errors.

This change uses no_keywords and check_positional to match CPython’s argument validation, validates attribute names before generic lookup, adds focused regression coverage for invalid calls, and removes the CPython 3.13 expected-failure marker for BuiltinTest.test_getattr.

Test plan

  • test/dynamo/test_misc.py -k wrong_args_raises: 5 passed
  • CPython 3.13 BuiltinTest.test_getattr under Dynamo using the installed-nightly/local-source overlay: passed
  • test/dynamo/test_tp_getattro.py -k test_getattr: 6 passed
  • Python formatting checks passed

Validated with Python 3.13.15 and CPU nightly torch
2.15.0.dev20260908. Clang-tidy, source-built, and CI validation remain outstanding.

Prepared with assistance from Codex. I reviewed and approved the changes before submission.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98

@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196526

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (8 Unrelated Failures)

As of commit 8f9b873 with merge base 82e11ef (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Sep 10, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@lalit10 lalit10 changed the title [dynamo] Validate getattr arguments before dispatch [dynamo] Validate getattr arguments before dispatch Sep 10, 2026
@lalit10
lalit10 marked this pull request as draft September 10, 2026 01:27
@lalit10
lalit10 force-pushed the fix-dynamo-getattr-arity branch from c22ef4d to df2cdda Compare September 10, 2026 02:01
@lalit10
lalit10 marked this pull request as ready for review September 10, 2026 02:23
@ezyang
ezyang requested a review from azahed98 September 10, 2026 15:52
@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 10, 2026
@guilhermeleobas

Copy link
Copy Markdown
Collaborator

Thanks @lalit10

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 22, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@huydhn

huydhn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot revert -m 'Sorry for reverting your change but it seems to break dynamo trunk tests' -c nosignal

test/cpython/v3_13/test_call.py::CFunctionCallsErrorMessages::test_varargs6_kw GH job link HUD commit link

cc @izaitsevfb As I'm not sure why the bot didn't revert this

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

pytorchmergebot added a commit that referenced this pull request Sep 23, 2026
This reverts commit 6bb7f66.

Reverted #196526 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it seems to break dynamo trunk tests ([comment](#196526 (comment)))
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@lalit10 your PR has been successfully reverted.

GetAttrBuiltinVariable indexed positional arguments before validating
getattr's signature. Too few arguments could raise an internal IndexError,
extra positional arguments could be ignored, and keyword arguments were not
rejected before dispatch. Non-string names could also surface as an internal
Dynamo error.

Use no_keywords and check_positional to match CPython's argument validation,
and validate attribute names before generic lookup. Add focused regression
coverage and remove the three CPython 3.13 expected-failure markers that now
pass, including the two missed by the original landing.

Test Plan:

```bash
PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_call.py
PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_builtin.py BuiltinTest.test_getattr
python test/dynamo/test_misc.py MiscTests -k wrong_args_raises
python test/dynamo/test_tp_getattro.py -k test_getattr
spin quicklint
```

The tests used working-tree Python sources overlaid on CPU nightly torch
2.15.0.dev20260922. A sweep of all 83 vendored CPython suites ran 6,527 tests
with no unexpected successes; test_bytes.py could not collect because
_testlimitedcapi was unavailable. The three other suite errors matched the
unmodified nightly.

Towards pytorch#195901, Item 3.

Prepared with assistance from Codex. I reviewed and approved the changes
before submission.
@lalit10
lalit10 force-pushed the fix-dynamo-getattr-arity branch from df2cdda to 8f9b873 Compare September 23, 2026 10:07
@lalit10

lalit10 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. The failure was caused by two stale expected-failure markers that I missed:

  • CFunctionCallsErrorMessages.test_varargs2min
  • CFunctionCallsErrorMessages.test_varargs6_kw

The getattr argument validation makes both tests pass, so the harness reported them as unexpected successes. I removed both markers, rebased onto the latest upstream/main, and force-pushed the update.

I reran the full Python 3.13 Dynamo test_call.py suite (184 tests), the focused getattr tests, and a broader vendored CPython sweep against the latest CPU nightly.

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorch-bot

pytorch-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

This PR needs to be approved by an authorized maintainer before merge.

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: trunk / linux-jammy-cuda13.2-py3.10-gcc11 / test (default, 13, 14, mt-l-x86aavx2-29-113-l4), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 2, 2, mt-l-x86iamx-8-64, unstable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 1, 2, mt-l-x86iamx-8-64, unstable)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@izaitsevfb

Copy link
Copy Markdown
Contributor

cc @izaitsevfb As I'm not sure why the bot didn't revert this

it was disabled due to ci:sev

@guilhermeleobas

Copy link
Copy Markdown
Collaborator

@izaitsevfb do we need to revert this one?

@izaitsevfb

Copy link
Copy Markdown
Contributor

@izaitsevfb do we need to revert this one?

ah, no, sorry, I was replying to Huy regarding why the autorevert didn't catch the original breakage and he had to revert it manually.

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

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo open source release notes: dynamo Reverted triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants