Skip to content

Commit

Permalink
638 Strange behaviour of CUDS remove (#659)
Browse files Browse the repository at this point in the history
* Do not put the wrapper in the added buffer.

* Have the assumption "the wrapper is not put in the added buffer" baked in the transport session.

* Have the assumption "the wrapper is not put in the added buffer" also baked in the unit tests. Notice how when `wrapper.add` is used, the wrapper is expected in the updated buffer instead of the added buffer. When `wrapper.add` is not used, the wrapper is not expected in neither buffer.
  • Loading branch information
kysrpex authored Jun 24, 2021
1 parent 415c676 commit 6ad48a4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
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

0 comments on commit 6ad48a4

Please sign in to comment.