Skip to content

Commit

Permalink
Temporary backport of some db changes ahead of Guillotina 4 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcarbs committed Sep 6, 2018
1 parent ab0123a commit 9c3dfd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
3.2.17 (unreleased)
3.2.16-1
-------------------

- Nothing changed yet.
- Temporary backport of some db changes ahead of Guillotina 4 upgrade


3.2.16 (2018-07-16)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.17.dev0
3.2.16-1
29 changes: 14 additions & 15 deletions guillotina/factory/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from guillotina.component import provide_utility
from guillotina.db import ROOT_ID
from guillotina.db.interfaces import IDatabaseManager
from guillotina.db.interfaces import IWriter
from guillotina.db.reader import reader
from guillotina.db.transaction_manager import TransactionManager
from guillotina.interfaces import IApplication
from guillotina.interfaces import IDatabase
Expand Down Expand Up @@ -112,7 +114,7 @@ async def async_get(self, key, suppress_events=True):
if key in self._items:
return self._items[key]
# check configured storages, see if there is a database registered under this name...
for storage_id, config in list_or_dict_items(app_settings['storages']):
for _, config in list_or_dict_items(app_settings['storages']):
factory = get_adapter(self, IDatabaseManager,
name=config['storage'], args=[config])
if key in await factory.get_names():
Expand Down Expand Up @@ -143,26 +145,23 @@ async def initialize(self):
request = make_mocked_request('POST', '/')
request._db_write_enabled = True
tm = request._tm = self.get_transaction_manager()
txn = await tm.begin(request=request)
txn = await tm.begin()

commit = False
try:
assert tm.get(request=request) == txn
root = await txn.get(ROOT_ID)
if root.__db_id__ is None:
root.__db_id__ = self._database_name
txn.register(root)
commit = True
await txn._strategy.retrieve_tid()
root = await tm._storage.load(txn, ROOT_ID)
if root is not None:
root = reader(root)
root._p_jar = txn
if root.__db_id__ is None:
root.__db_id__ = self._database_name
await tm._storage.store(ROOT_ID, 0, IWriter(root), root, txn)
except KeyError:
from guillotina.db.db import Root
root = Root(self._database_name)
txn.register(root, new_oid=ROOT_ID)
commit = True

if commit:
await tm._storage.store(ROOT_ID, 0, IWriter(root), root, txn)
finally:
await tm.commit(txn=txn)
else:
await tm.abort(txn=txn)

async def open(self):
"""Return a database Connection for use by application code.
Expand Down

0 comments on commit 9c3dfd9

Please sign in to comment.