[ckan-changes] [ckan/ckan] 38aae9: [#1725] Fix bug where we're trying to close using ...

GitHub noreply at github.com
Wed Jun 11 13:33:43 UTC 2014


  Branch: refs/heads/1725-extend-datastore
  Home:   https://github.com/ckan/ckan
  Commit: 38aae975d87620eea8a71019813ebc2e7c9fb99b
      https://github.com/ckan/ckan/commit/38aae975d87620eea8a71019813ebc2e7c9fb99b
  Author: Vitor Baptista <vitor at vitorbaptista.com>
  Date:   2014-06-11 (Wed, 11 Jun 2014)

  Changed paths:
    M ckanext/datastore/plugin.py

  Log Message:
  -----------
  [#1725] Fix bug where we're trying to close using a null connection

The problem is that the code was:

```python
try:
    connection = self.read_engine.connect()
    # ...
finally:
    connection.close()
```

But if `self.read_engine.connect()` raised an exception, `connection` would
never be defined, but we would still try to call `connection.close()`, which
would in turn raise:

```
UnboundLocalError: local variable 'connection' referenced before assignment
```

This would also hide the exception raised when calling `.connect()`, so we
wouldn't know what was the original problem.

This commit fixes it by making sure the `connection` variable exists.




More information about the ckan-changes mailing list