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

Toggleable context injection #72

Open
jzmiller1 opened this issue Nov 24, 2022 · 2 comments
Open

Toggleable context injection #72

jzmiller1 opened this issue Nov 24, 2022 · 2 comments

Comments

@jzmiller1
Copy link
Contributor

jzmiller1 commented Nov 24, 2022

This is one of those late night questions so forgive me if I'm missing something obvious. I'm getting an error of this type:

TransactionManagementError at /admin/djstripe/apikey/add/
An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

The pghistory context injection is included in the traceback and I was curious if there was an easy way to disable the context injection or pghistory in general?

/usr/local/lib/python3.10/site-packages/pghistory/runtime.py, line 51, in _inject_history_context is going off before self.db.validate_no_broken_transaction() in /django/db/backends/utils.py

I attempted following the suggestion in https://django-pghistory.readthedocs.io/en/2.5.1/performance.html about setting settings.PGHISTORY_CONTEXT_FIELD to None but bumped into some issues on that path as well:

File "/usr/local/lib/python3.10/site-packages/pghistory/core.py", line 656, in _model_wrapper
  create_event_model(
File "/usr/local/lib/python3.10/site-packages/pghistory/core.py", line 516, in create_event_model
  context_field = _get_context_field(context_field=context_field, context_fk=context_fk)
File "/usr/local/lib/python3.10/site-packages/pghistory/core.py", line 399, in _get_context_field
  context_field = config.context_field()
File "/usr/local/lib/python3.10/site-packages/pghistory/config.py", line 70, in context_field
  assert isinstance(context_field, (ContextForeignKey, ContextJSONField))
@wesleykendall
Copy link
Collaborator

@jzmiller1 sorry for the delay on this. This issue should be fixed in #95 when deployed. I now check for an errored transaction before setting context in the SQL.

The SQL variable injection is quite complex. I use this approach in a few libraries too. I'm planning to break up this SQL injection into its own library and then allow users to better configure its behavior (i.e. instead of injecting variables into the SQL, you can tell it to just issue separate SQL commands to set the variables if you don't care about extra queries).

Tracking this feature at #96

@jzmiller1
Copy link
Contributor Author

Hey thanks for the update and no need to be sorry! I love all your work on your pg projects. Thanks for it!

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

2 participants