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

Fix deleting when prop index is None #1200

Merged
merged 4 commits into from Apr 10, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -19,6 +19,7 @@ Bugfixes
--------

- When using ``synapse.tools.cmdr``, issuing ctrl-c to cancel a running command in could result in the Telepath Proxy object being fini'd. This has been resolved by adding a signal handler to the ``synapse.lib.cli.Cli`` class which is registered by cmdr. (`#1199 <https://github.com/vertexproject/synapse/pull/1199>`_)
- Fix an issue where deleting a property which has no index failed. (`#1200 <https://github.com/vertexproject/synapse/pull/1200>`_)

Improved Documentation
----------------------
Expand Down
40 changes: 23 additions & 17 deletions synapse/lib/lmdblayer.py
Expand Up @@ -224,11 +224,12 @@ async def editNodeNdef(self, oldv, newv):
# for the *<form> prop, the byprop index has <form><00><00><indx>
if proputf8[0] == 42:

oldpropkey = oldfenc + b'\x00' + indx
newpropkey = newfenc + b'\x00' + newnindx

if not self.layrslab.delete(oldpropkey, pvoldval, db=self.byprop): # pragma: no cover
logger.warning(f'editNodeNdef del byprop missing for {repr(oldv)} {repr(oldpropkey)}')
if indx is not None:
oldpropkey = oldfenc + b'\x00' + indx
if not self.layrslab.delete(oldpropkey, pvoldval, db=self.byprop): # pragma: no cover
logger.warning(f'editNodeNdef del byprop missing for {repr(oldv)} {repr(oldpropkey)}')

self.layrslab.put(newpropkey, pvnewval, dupdata=True, db=self.byprop)

Expand Down Expand Up @@ -276,17 +277,19 @@ async def _storBuidSet(self, oper):
proputf8 = lkey[32:]
valu, indx = s_msgpack.un(lval)

# <prop><00><indx>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we not have migration / regression tests for this function???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

propindx = proputf8 + b'\x00' + indx
if indx is not None:

if proputf8[0] in (46, 35): # ".univ" or "#tag"
self.layrslab.put(propindx, pvnewval, dupdata=True, db=self.byuniv)
self.layrslab.delete(propindx, pvoldval, db=self.byuniv)
# <prop><00><indx>
propindx = proputf8 + b'\x00' + indx

bypropkey = fenc + propindx
if proputf8[0] in (46, 35): # ".univ" or "#tag"
self.layrslab.put(propindx, pvnewval, dupdata=True, db=self.byuniv)
self.layrslab.delete(propindx, pvoldval, db=self.byuniv)

self.layrslab.put(bypropkey, pvnewval, db=self.byprop)
self.layrslab.delete(bypropkey, pvoldval, db=self.byprop)
bypropkey = fenc + propindx

self.layrslab.put(bypropkey, pvnewval, db=self.byprop)
self.layrslab.delete(bypropkey, pvoldval, db=self.byprop)

self.layrslab.put(newb + proputf8, lval, db=self.bybuid)
self.layrslab.delete(lkey, db=self.bybuid)
Expand Down Expand Up @@ -343,11 +346,12 @@ def _storPropSetCommon(self, buid, penc, bpkey, pvpref, univ, valu, indx):
if byts is not None:

oldv, oldi = s_msgpack.un(byts)
if oldi is not None:

self.layrslab.delete(pvpref + oldi, pvvalu, db=self.byprop)
self.layrslab.delete(pvpref + oldi, pvvalu, db=self.byprop)

if univ:
self.layrslab.delete(penc + oldi, pvvalu, db=self.byuniv)
if univ:
self.layrslab.delete(penc + oldi, pvvalu, db=self.byuniv)

if indx is not None:

Expand Down Expand Up @@ -379,10 +383,12 @@ def _storPropDel(self, oper):
oldv, oldi = s_msgpack.un(byts)

pvvalu = s_msgpack.en((buid,))
self.layrslab.delete(fenc + penc + oldi, pvvalu, db=self.byprop)

if univ:
self.layrslab.delete(penc + oldi, pvvalu, db=self.byuniv)
if oldi is not None:
self.layrslab.delete(fenc + penc + oldi, pvvalu, db=self.byprop)

if univ:
self.layrslab.delete(penc + oldi, pvvalu, db=self.byuniv)

def _storSplicesSync(self, splices):
self.splicelog.save(splices)
Expand Down
9 changes: 9 additions & 0 deletions synapse/tests/test_cortex.py
Expand Up @@ -2540,3 +2540,12 @@ async def test_cortex_hive(self):
await core.hive.set(('visi',), 200)
async with core.getLocalProxy(share='cortex/hive') as hive:
self.eq(200, await hive.get(('visi',)))

async def test_delevent(self):
''' Tests deleting a node with a property without an index '''
async with self.getTestCore() as core:
async with await core.snap() as snap:
evt_guid = s_common.guid('evt')
node = await snap.addNode('graph:event', evt_guid, {'name': 'an event', 'data': 'beep'})

await node.delete(force=True)