Skip to content

FIX Only include called from portion of message if not blank #11729

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

Merged

Conversation

emteknetnz
Copy link
Member

Issue #11699

@emteknetnz emteknetnz marked this pull request as ready for review May 14, 2025 00:24
@emteknetnz emteknetnz force-pushed the pulls/5.4/depr-called-from branch from b5903ba to cdffb4d Compare May 14, 2025 00:35
@emteknetnz emteknetnz changed the title FIX Only added called from portion of message if not blank FIX Only include called from portion of message if not blank May 14, 2025
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Do we know why it's not identifying where it's called from in the first place?

@emteknetnz
Copy link
Member Author

We have this code in Deprecation::notice();

    // Getting a backtrace is slow, so we only do it if we need it
    $backtrace = [];
    
    // Get the calling scope
    if ($scope == Deprecation::SCOPE_METHOD) {
        $backtrace = debug_backtrace(0);
        $caller = Deprecation::get_called_method_from_trace($backtrace, 1);
    } elseif ($scope == Deprecation::SCOPE_CLASS) {
        $backtrace = debug_backtrace(0);
        $caller = isset($backtrace[1]['class']) ? $backtrace[1]['class'] : '(unknown)';
    } else {
        $caller = false;
    }

Means that we only get the backtrace if scope is either method or class. The db:tasks deprecation message above came from SCOPE_GLOBAL

I don't have the background as to why we don't get the stacktrace in all cases, though there would presumably be a reason for the code to be the way it is. Adding support for global messages is more then I'm comfortably doing at this stage as I can see it turning into a large time sink.

I think the information provided in the message is good enough for end-users. If you find any other instances of deprecation messages not being useful enough to pinpoint where they are coming from then perhaps we resolve in a new card.

@GuySartorelli
Copy link
Member

Ohhh interesting. Yeah agreed that adding trace for globally scoped items is out of scope for this card. I had assumed it was something not working, not something completely not implemented.

We probably need to rebuild the way we're dealing with the trace anyway, that code is a bit of a jungle, so I'd want to improve that before adding more to it.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

LGTM

@GuySartorelli GuySartorelli merged commit 823f36e into silverstripe:5.4 May 14, 2025
17 checks passed
@GuySartorelli GuySartorelli deleted the pulls/5.4/depr-called-from branch May 14, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants