Skip to content

refactor: remove the unused Sockets.__getattribute__ override - #12966

Open
bhaskargurram-ai wants to merge 3 commits into
deepset-ai:mainfrom
bhaskargurram-ai:fix/sockets-getattribute-attribute-name
Open

bhaskargurram-ai wants to merge 3 commits into
deepset-ai:mainfrom
bhaskargurram-ai:fix/sockets-getattribute-attribute-name

Conversation

@bhaskargurram-ai

@bhaskargurram-ai bhaskargurram-ai commented Sep 25, 2026 •

Copy link
Copy Markdown

Proposed Changes:

Sockets.__getattribute__ looked up a _sockets attribute that no instance has, so it raised and caught AttributeError on every attribute access and never returned a socket. Socket access already goes through the copies __init__ and __setitem__ put in __dict__. As suggested in review, this removes the override instead of fixing it.

How did you test it?

test/core/component and test/core/pipeline pass (the only failures are missing optional deps and fail identically on main). Micro-benchmark of component.__haystack_input__.<socket>: 728 ns on main, 51 ns with this change.

__getattribute__ looked up a `_sockets` attribute, but the one __init__
assigns is `_sockets_dict`. The lookup raised AttributeError on every
attribute access and fell through to object.__getattribute__, so the
intended fast path never ran.

Socket access still worked, but only through the copy __init__ places in
__dict__ -- which made the dead branch look load-bearing and put an
exception on the path of every attribute access.

Reading the right name makes the branch live: 200k socket attribute
accesses drop from 0.125s to 0.031s. External behaviour is unchanged,
since the __dict__ copy already shadowed class attributes for the same
names.

Fixes deepset-ai#12939
@bhaskargurram-ai
bhaskargurram-ai requested a review from a team as a code owner September 25, 2026 21:28
@bhaskargurram-ai
bhaskargurram-ai requested review from julian-risch and removed request for a team September 25, 2026 21:28
@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@bhaskargurram-ai is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @bhaskargurram-ai, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from julian-risch September 25, 2026 22:51
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Sep 25, 2026
@HaystackBot
HaystackBot marked this pull request as draft September 25, 2026 22:51
@HaystackBot
HaystackBot marked this pull request as ready for review September 25, 2026 23:25
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Sep 25, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @bhaskargurram-ai! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@bhaskargurram-ai

Copy link
Copy Markdown
Author

Hi @julian-risch, gentle ping on this one when you have a moment. Sockets.getattribute looked up _sockets instead of _sockets_dict, so the fast path never ran: 200k socket attribute accesses take 0.031 s with the fix vs 0.125 s before. The CLA is signed. Thanks!

@github-actions github-actions Bot added the P2 Medium priority, add to the next sprint if no P1 available label Oct 8, 2026
Comment thread releasenotes/notes/fix-sockets-getattribute-lookup-7c31a9f4e28b5d16.yaml Outdated
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/core/component
  sockets.py 131
Project Total  

This report was generated by python-coverage-comment-action

Comment thread haystack/core/component/sockets.py Outdated
@@ -125,7 +125,7 @@ def _component_name(self) -> str:

def __getattribute__(self, name: Any) -> Any:

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.

This override has never run since it was added in #6916 because it looked up _sockets, and socket access has always gone through the copy __init__ and __setitem__ put in __dict__. Could we remove the __getattribute__ override instead? I tried that locally: test/core/component and test/core/pipeline pass, apart from the new test that deletes from io.__dict__, and socket lookup is about 3x faster than with this change. WDYT?

Comment thread test/core/component/test_sockets.py Outdated

assert io.input_1 == comp.__haystack_input__._sockets_dict["input_1"] # type: ignore[attr-defined]

def test_getattribute_does_not_shadow_methods_or_private_attributes(self):

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.

This test passes on main as well since no socket name collides with get or _sockets_dict. Lets remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, removed the override in 2b1a63d and dropped both tests that only exercised it. Socket access is about 14x faster than main in my micro-benchmark (728 ns → 51 ns). Also switched the release note to double backticks earlier (2fb3355).

The override never returned a socket (see the previous commit), and socket
attribute access already goes through the __dict__ copies made by __init__
and __setitem__. Removing it, as suggested in review, makes socket attribute
access about 14x faster than on main (728 ns -> 51 ns per access in a
micro-benchmark). Drop the two tests that only exercised the override.
@bhaskargurram-ai bhaskargurram-ai changed the title fix: read _sockets_dict in Sockets.__getattribute__ refactor: remove the unused Sockets.__getattribute__ override Oct 9, 2026
@github-actions github-actions Bot removed the P2 Medium priority, add to the next sprint if no P1 available label Oct 9, 2026

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants