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

pghistory.context used when pghistory.middleware.HistoryMiddleware throws AttributeError: 'NoneType' object has no attribute 'nextset' #117

Open
JimFuller-RedHat opened this issue Mar 28, 2024 · 0 comments

Comments

@JimFuller-RedHat
Copy link

JimFuller-RedHat commented Mar 28, 2024

When pghistory.middleware.HistoryMiddleware is installed as a django middleware ... any usage of with pghistory.context() within the django app throws throws AttributeError: 'NoneType' object has no attribute 'nextset'

here is the last of the error

File ~/src/#####/venv/lib64/python3.9/site-packages/pghistory/runtime.py:89, in _inject_history_context(execute, sql, params, many, context)
     83     sql = (
     84         "SELECT set_config('pghistory.context_id', %s, true), "
     85         "set_config('pghistory.context_metadata', %s, true); "
     86     ) + sql
     87     params = [str(_tracker.value.id), serialized_metadata, *(params or ())]
---> 89 return _execute_wrapper(execute(sql, params, many, context))

File ~/src/#####/venv/lib64/python3.9/site-packages/pghistory/runtime.py:72, in _execute_wrapper(execute_result)
     70 def _execute_wrapper(execute_result):
     71     if utils.psycopg_maj_version == 3:
---> 72         while execute_result.nextset():
     73             pass
     74     return execute_result

AttributeError: 'NoneType' object has no attribute 'nextset'

looks like we need a check on execute_result before calling nextset().

pghistory/runtime.py#70

def _execute_wrapper(execute_result):
    if utils.psycopg_maj_version == 3:
        if execute_result:
            while execute_result.nextset():
                pass
    return execute_result

seems to fix though I am clueless about the 'big picture'

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