Repository navigation
Fix infinite recursion on links that point back to themselves - #336
Merged
Merged
Conversation
Contributor
Danger ReportNo issues found. |
When a link's resource has a link of the same name pointing to the same URL (e.g. a `sub_nodes` collection whose `_links.sub_nodes` is itself), `Link#respond_to_missing?` and `#delegate_method` followed that link forever, fetching it on every level until `SystemStackError`. Stop delegating to a link with the same URL, and have `Link#each` raise `Hyperclient::SelfReferencingLinkError` pointing to `_embedded` instead. Closes codegram#232. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW
dblock
force-pushed
the
dblock/self-link-recursion
branch
from
November 22, 2026 13:51
68c072a to
278d7f8
Compare
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #232.
Problem
When a link's resource has a link of the same name pointing to the same URL, for example a
sub_nodescollection whose own_links.sub_nodesis itself and whose items are embedded under a different key,api.item.sub_nodes.map(&:name)raisedSystemStackError: stack level too deep.Link#eachcallsrespond_to?(@key), andLink#respond_to_missing?(and#delegate_method) followed_resource.sub_nodesto a newLinkto the same URL, asked it the same question, and so on forever, fetching the URL on every level.This is unrelated to Ruby 3; it reproduces on current Ruby.
Fix
Link#respond_to_missing?andLink#delegate_methodno longer delegate to aLinkwith the same URL.Link#eachraisesHyperclient::SelfReferencingLinkError("The sub_nodes link at … links back to itself, use _embedded to iterate over embedded items.") instead of recursing._embedded.<key>still works.Validation
each,respond_to?and nil-delegation paths, and for a same-name link to a different URL; the self-referencing specs fail without the fix.bundle exec rakelocally on Ruby 4.0.9: 174 tests, 32 spinach steps, RuboCop clean.🤖 Generated with Claude Code
https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW