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

Add some clue from where in the code the update came from #1288

Open
PetrDlouhy opened this issue Dec 21, 2023 · 0 comments
Open

Add some clue from where in the code the update came from #1288

PetrDlouhy opened this issue Dec 21, 2023 · 0 comments

Comments

@PetrDlouhy
Copy link

PetrDlouhy commented Dec 21, 2023

Problem Statement
As I added simple history to existing project I am often dealing with a situation that I see history change but it have blank change_reason and I don't know where it came from.
Optimally I would like to see full trace from the save() up.

I tried to add the _change_reason to various places in the code, but it could take quite some time to have it everywhere regardless the burden it would add to the code.
I would like to have _change_reason only on places in the code where it brings some additional benefit over just knowing where the change came from.

Describe the solution you'd like
I am not sure what the correct solution is. I am sure that for example introducing new field with full trace could be too expensive for many of the current implementations.

This functionality could have been made somehow optional, for example as some parameter to HistoricalRecords.

Also there is possibility to just fill in something to the _change_reason if it is blank.
I have found a way to do this as a bit dirty hotfix in my project just by adding this code to /history_register/__init__.py:

import traceback

from simple_history import utils


# Modify get_change_message to include change reason
_original_get_change_reason_from_object = utils.get_change_reason_from_object


def get_change_reason_from_object(obj):
    original_reason = _original_get_change_reason_from_object(obj)
    if not original_reason:
        blenderhub_ts = []
        for t in traceback.format_stack():
            if "/blenderhub" in t and "/history_register/" not in t:
                blenderhub_ts.append(
                    t.split("apps/")[-1].split(", in")[0].replace('", line ', ":").strip()
                )
        return "|".join(blenderhub_ts)[-100:]
    return original_reason


utils.get_change_reason_from_object = get_change_reason_from_object
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

No branches or pull requests

1 participant