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

Small storage update fixes #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ snovault
Change Log
----------

7.1.2
=====

* In ``RDBStorage.update``:
* Use session.begin_nested for better stack hygiene.
* Better error message on integrity error to acknowledge possibility
of both UUID conflit *and* undefined UUID.


7.1.1
=====

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicsnovault"
version = "7.1.1"
version = "7.1.1.1b0" # to become "7.1.2"
description = "Storage support for 4DN Data Portals."
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
27 changes: 13 additions & 14 deletions snovault/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,18 @@ def create(self, item_type, rid):

def update(self, model, properties=None, sheets=None, unique_keys=None, links=None):
session = self.DBSession()
sp = session.begin_nested()
try:
session.add(model)
self._update_properties(model, properties, sheets)
if links is not None:
self._update_rels(model, links)
if unique_keys is not None:
keys_add, keys_remove = self._update_keys(model, unique_keys)
sp.commit()
except (IntegrityError, FlushError):
sp.rollback()
else:
return
with session.begin_nested() as sp:
try:
session.add(model)
self._update_properties(model, properties, sheets)
if links is not None:
self._update_rels(model, links)
if unique_keys is not None:
keys_add, keys_remove = self._update_keys(model, unique_keys)
sp.commit()
return
except (IntegrityError, FlushError):
sp.rollback()

# Try again more carefully
try:
Expand All @@ -497,7 +496,7 @@ def update(self, model, properties=None, sheets=None, unique_keys=None, links=No
self._update_rels(model, links)
session.flush()
except (IntegrityError, FlushError):
msg = 'UUID conflict'
msg = 'Cannot update because of one or more conflicting (or undefined) UUIDs'
raise HTTPConflict(msg)
assert unique_keys is not None
conflicts = [pk for pk in keys_add if session.query(Key).get(pk) is not None]
Expand Down
8 changes: 4 additions & 4 deletions snovault/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import time
import tempfile
# import os
# import time
# import tempfile
import pytest
import logging
import subprocess
# import subprocess

from ..elasticsearch.indexer_queue import QueueManager

Expand Down
4 changes: 3 additions & 1 deletion snovault/tests/test_embedding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import time
# import time

from dcicutils.misc_utils import ignored
from dcicutils.qa_utils import notice_pytest_fixtures, Retry, Eventually
Expand Down Expand Up @@ -112,9 +112,11 @@ def test_linked_uuids_object(content, dummy_request, threadlocals):
# needed to track _linked_uuids
dummy_request._indexing_view = True
dummy_request.embed('/testing-link-sources-sno/', sources[0]['uuid'], '@@object')

def my_assertions():
assert dummy_request._linked_uuids == {('16157204-8c8f-4672-a1a4-14f4b8021fcd', 'TestingLinkSourceSno')}
assert dummy_request._rev_linked_uuids_by_item == {}

Eventually.call_assertion(my_assertions)


Expand Down
2 changes: 1 addition & 1 deletion snovault/tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import mock
import pytest
import re
import transaction as transaction_management
# import transaction as transaction_management
import uuid
import boto3

Expand Down