Skip to content

Commit

Permalink
Fix layer.getPropCount for univ props (#2073)
Browse files Browse the repository at this point in the history
* Fix layer.getPropCount for univ props
  • Loading branch information
Cisphyx committed Feb 4, 2021
1 parent a4b2959 commit 02daf6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions synapse/lib/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,17 @@ async def getPropCount(self, formname, propname=None, maxsize=None):

return await self.layrslab.countByPref(abrv, db=self.byprop, maxsize=maxsize)

async def getUnivPropCount(self, propname, maxsize=None):
'''
Return the number of universal property rows in the layer for the given prop.
'''
try:
abrv = self.getPropAbrv(None, propname)
except s_exc.NoSuchAbrv:
return 0

return await self.layrslab.countByPref(abrv, db=self.byprop, maxsize=maxsize)

async def liftByTag(self, tag, form=None):

try:
Expand Down
2 changes: 2 additions & 0 deletions synapse/lib/stormtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4117,6 +4117,8 @@ async def _methGetPropCount(self, propname, maxsize=None):

if prop.isform:
todo = s_common.todo('getPropCount', prop.name, None, maxsize=maxsize)
elif prop.isuniv:
todo = s_common.todo('getUnivPropCount', prop.name, maxsize=maxsize)
else:
todo = s_common.todo('getPropCount', prop.form.name, prop.name, maxsize=maxsize)

Expand Down
7 changes: 7 additions & 0 deletions synapse/tests/test_lib_stormtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3382,9 +3382,16 @@ async def test_stormtypes_layer_counts(self):
self.eq(3, await core.callStorm('return($lib.layer.get().getTagCount(foo.bar))'))
self.eq(2, await core.callStorm('return($lib.layer.get().getTagCount(foo.bar, formname=inet:ipv4))'))

self.eq(6, await core.callStorm("return($lib.layer.get().getPropCount('.created'))"))
self.eq(2, await core.callStorm("return($lib.layer.get().getPropCount(inet:ipv4.created))"))
self.eq(0, await core.callStorm("return($lib.layer.get().getPropCount('.seen'))"))

with self.raises(s_exc.NoSuchProp):
await core.callStorm('return($lib.layer.get().getPropCount(newp:newp))')

with self.raises(s_exc.NoSuchProp):
await core.callStorm("return($lib.layer.get().getPropCount('.newp'))")

async def test_lib_stormtypes_cmdopts(self):
pdef = {
'name': 'foo',
Expand Down

0 comments on commit 02daf6f

Please sign in to comment.