Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safety guard when the self.class is not responding to method identifier #2870

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

navidemad
Copy link
Contributor

Overview

Issue: #2869

Due to a recent change in the gem view_component
ViewComponent/view_component@451543a#diff-b69c75ffd85596e0b5fca1327059ecf3b2930f3f77004c78a268fa85e8ec8d9eL601

We were getting:
ActionView::Template::Error: undefined method identifier'`

The method identifier on their base class has been removed.
This pull request make sure it returns nil if it is not found.

@CLAassistant
Copy link

CLAassistant commented Sep 28, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the community To tag external issues and PRs submitted by the community label Sep 28, 2024
@joelhawksley
Copy link

👋🏻 ViewComponent maintainer here! FYI, this method should never have been used as it was marked private (and not documented in the API docs) ViewComponent/view_component@v3.14.0...v3.15.0#diff-b69c75ffd85596e0b5fca1327059ecf3b2930f3f77004c78a268fa85e8ec8d9eL601.

@fallwith
Copy link
Contributor

Hi @navidemad, thanks very much for creating the GitHub Issue and submitting this fix. Very much appreciated. Your change looks good and will go out in our next agent release.

Hi @joelhawksley. Point well taken. Our preferred approach for gathering metrics and other information from a library is to leverage public APIs. We also often submit PRs against libraries and/or work with maintainers to deliver new or enhanced APIs whenever we need something that doesn't already exist. We don't always take the preferred approach and fall back on using private APIs or monkeypatching though. This can be for any one of several reasons, including shifting schedules and priorities that see us do something to get some coverage in place - especially when in response to a customer feature request - as quickly as possible. In the particular case of ViewComponent, I think we should revisit our instrumentation at some point and take another look at what is possible by consuming the ActiveSupport notifications the library produces. ViewComponent's own lib/view_component/instrumentation.rb, for example, uses self.class.source_location for the identifier. We ought to see if we can simply consume those notifications or if not at least make the same self.class.source_location call for the identifier. I will create a GitHub issue to remind us to look into doing so. For now, this PR is an improvement upon what we already have so I'll go ahead and merge it.

@joelhawksley
Copy link

@fallwith makes sense to me. I'd be open to formally exposing the source_location as a public API if you'd find it useful. Let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community To tag external issues and PRs submitted by the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants