[ckan-changes] [ckan/ckan] 2a340f: [#5137] [#5137] Fix Datapusher exceptions on 2.9

Sergey noreply at github.com
Wed Jan 29 23:32:39 UTC 2020


  Branch: refs/heads/master
  Home:   https://github.com/ckan/ckan
  Commit: 2a340f85a21e7e8c563deedba675f967040dfbb3
      https://github.com/ckan/ckan/commit/2a340f85a21e7e8c563deedba675f967040dfbb3
  Author: amercader <amercadero at gmail.com>
  Date:   2020-01-24 (Fri, 24 Jan 2020)

  Changed paths:
    M ckanext/datapusher/plugin.py
    M ckanext/datapusher/tests/test.py

  Log Message:
  -----------
  [#5137] [#5137] Fix Datapusher exceptions on 2.9

Fixes #5137, #4751

This was originally reported in the issues above. On 2.9, enabling the
DataPusher causes an exception at the end of the dataset creation
process, when submitting the resources. The stack trace looks like this:

```
  File "/home/adria/dev/pyenvs/ckan/lib/python2.7/site-packages/flask/views.py", line 163, in dispatch_request
    return meth(*args, **kwargs)
  File "/home/adria/dev/pyenvs/ckan/src/ckan/ckan/views/resource.py", line 242, in post
    get_action(u'resource_create')(context, data)
  File "/home/adria/dev/pyenvs/ckan/src/ckan/ckan/logic/__init__.py", line 472, in wrapped
    result = _action(context, data_dict, **kw)
  File "/home/adria/dev/pyenvs/ckan/src/ckan/ckan/logic/action/create.py", line 330, in resource_create
    model.repo.commit()
  File "/home/adria/dev/pyenvs/ckan/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 162, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/home/adria/dev/pyenvs/ckan/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1027, in commit
    self.transaction.commit()
  File "/home/adria/dev/pyenvs/ckan/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 494, in commit
    self._prepare_impl()
  File "/home/adria/dev/pyenvs/ckan/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 464, in _prepare_impl
    stx = self.session.transaction
AttributeError: 'NoneType' object has no attribute 'transaction'
```

As with all SQLAlchemy session issues and DataPusher ones this one took
a while to track, but essentially it boiled down to what @davidread
explained [here](https://stackoverflow.com/a/56094135/235993)

The `datapusher` plugin used the `notify` hook to listen to resource
changes. This was fired from `resource_create` which had started a
transaction. The plugin then called `datapusher_submit` which in turns
calls `task_status_update`, which commits and clears the Session causing
troubles later on.

How this had been working up until 2.8 I don't know and I'm not keen on
finding out to be honest. This PR refactors the `datapusher` plugin to
use the `IResourceController.after_create` and
`IResourceUrlChange.notify` hooks, which are called after commit.

It adds two tests that failed before the patch as well.


  Commit: 4afed394881b6ef20daf07d3531832a4f4ab3af4
      https://github.com/ckan/ckan/commit/4afed394881b6ef20daf07d3531832a4f4ab3af4
  Author: Sergey <tonnydexter at gmail.com>
  Date:   2020-01-30 (Thu, 30 Jan 2020)

  Changed paths:
    M ckanext/datapusher/plugin.py
    M ckanext/datapusher/tests/test.py

  Log Message:
  -----------
  Merge pull request #5173 from ckan/5137-datapusher-errors-2.9

[#5137] Fix Datapusher exceptions on 2.9


Compare: https://github.com/ckan/ckan/compare/2eac9a2f9200...4afed394881b



More information about the ckan-changes mailing list