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

638 Strange behaviour of CUDS remove #659

Merged
merged 5 commits into from
Jun 24, 2021
Merged
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
11 changes: 7 additions & 4 deletions osp/core/session/transport/transport_session_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import tempfile
import urllib.parse
from osp.core.namespaces import cuba
from osp.core.session.buffers import BufferType
from osp.core.session.wrapper_session import check_consumes_buffers, \
WrapperSession
Expand Down Expand Up @@ -85,10 +86,12 @@ def _store(self, cuds_object):
super()._store(cuds_object)
self._engine.send(INITIALIZE_COMMAND,
json.dumps(data))
logger.debug("Remove %s from added buffer in context %s of session"
" %s" % (cuds_object, self._current_context, self))
del self._buffers[self._current_context][
BufferType.ADDED][cuds_object.uid]
if not cuds_object.is_a(cuba.Wrapper):
logger.debug("Remove %s from added buffer in context %s of "
"session %s" % (cuds_object,
self._current_context, self))
del self._buffers[self._current_context][
BufferType.ADDED][cuds_object.uid]
return
super()._store(cuds_object)

Expand Down
6 changes: 2 additions & 4 deletions osp/core/session/wrapper_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import rdflib
from abc import abstractmethod
from osp.core.namespaces import cuba
from osp.core.session.session import Session
from osp.core.session.result import returns_query_result
from osp.core.utils.wrapper_development import clone_cuds_object, \
Expand Down Expand Up @@ -161,7 +162,6 @@ def refresh(self, *cuds_or_uids):
def _get_full_graph(self):
"""Get the triples in the core session."""
from osp.core.utils.simple_search import find_cuds_object
from osp.core.namespaces import cuba

for cuds_object in find_cuds_object(lambda x: True,
self._registry.get(self.root),
Expand Down Expand Up @@ -195,7 +195,6 @@ def log_buffer_status(self, context):

def _store_checks(self, cuds_object):
# Check if root is wrapper and wrapper is root
from osp.core.namespaces import cuba
if cuds_object.is_a(cuba.Wrapper) and self.root is not None \
and self.root != cuds_object.uid:
raise RuntimeError("Only one wrapper is allowed per session")
Expand Down Expand Up @@ -242,12 +241,11 @@ def _store(self, cuds_object):
logger.debug("Added %s to updated buffer in %s of %s"
% (cuds_object, self._current_context, self))
updated[cuds_object.uid] = cuds_object
else:
elif not cuds_object.is_a(cuba.Wrapper):
if logger.level == logging.DEBUG:
logger.debug("Added %s to added buffer in %s of %s"
% (cuds_object, self._current_context, self))
added[cuds_object.uid] = cuds_object

# store
super()._store(cuds_object)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_session_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_buffers(self):
w.session.prune()

self.assertEqual(session._buffers, [
[{cw.uid: cw, w.uid: w}, dict(), dict()],
[{cw.uid: cw}, {w.uid: w}, dict()],
[dict(), dict(), dict()]])

w.session._reset_buffers(BufferContext.USER)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_transport_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def testDeserialize(self):
def test_import_rdf(self):
"""Test the import rdf functionality."""
with TestWrapperSession() as session:
w = city.CityWrapper(session=session)
city.CityWrapper(session=session)
g = json_to_rdf(CUDS_LIST_NON_PARTITIONED, rdflib.Graph())
cuds_objects = import_rdf(g, session, BufferContext.USER)
self.assertEqual(len(cuds_objects), 4)
Expand All @@ -380,7 +380,7 @@ def test_import_rdf(self):
{1, 2, 3, 123})
self.assertEqual(set(session._buffers[0][0]), {
uuid.UUID(int=1), uuid.UUID(int=2), uuid.UUID(int=3),
uuid.UUID(int=123), w.uid
uuid.UUID(int=123)
})
self.assertEqual(session._buffers[0][1:], [{}, {}])
self.assertEqual(session._buffers[1], [{}, {}, {}])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_create_recycle(self):
w.uid})
self.assertIs(session._registry.get(b.uid), b)
self.assertEqual(session._buffers, [
[{w.uid: w}, dict(), dict()],
[dict(), dict(), dict()],
[{b.uid: b}, dict(), dict()]]
)

Expand All @@ -265,7 +265,7 @@ def test_create_recycle(self):
{a.uid, x.uid})
self.assertIs(default_session._registry.get(a.uid), a)
self.assertEqual(session._buffers, [
[{w.uid: w, x.uid: x}, {c.uid: c},
[{x.uid: x}, {c.uid: c},
dict()],
[dict(), dict(), dict()]]
)
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_create_from_cuds_object(self):
w.uid})
self.assertIs(session._registry.get(b.uid), b)
self.assertEqual(session._buffers, [
[{w.uid: w}, dict(), dict()],
[dict(), dict(), dict()],
[{b.uid: b}, dict(), dict()]])

b.name = "Emmendingen"
Expand All @@ -317,7 +317,7 @@ def test_create_from_cuds_object(self):
{a.uid, x.uid, y.uid})
self.assertIs(default_session._registry.get(a.uid), a)
self.assertEqual(session._buffers, [
[{x.uid: x, w.uid: w}, {c.uid: c},
[{x.uid: x}, {c.uid: c},
dict()],
[dict(), dict(), dict()]])

Expand Down