# HG changeset patch # User drewp@bigasterisk.com # Date 1685402146 25200 # Node ID a47c8224e97fd5d1dd9c61a00b4d2a66417a4a72 # Parent d195a5f5013714eacc228b6203ce00389a5069db raise if we see xsd:float or xsd:double, since i want to be using xsd:decimal everywhere. This revealed a bug where adds/dels iterables got consumed(!) diff -r d195a5f50137 -r a47c8224e97f rdfdb/patch.py --- a/rdfdb/patch.py Mon May 29 16:14:17 2023 -0700 +++ b/rdfdb/patch.py Mon May 29 16:15:46 2023 -0700 @@ -1,5 +1,6 @@ +import itertools import json -from typing import Iterable, Optional, Tuple +from typing import Iterable, Optional, Tuple, cast from rdflib import ConjunctiveGraph, Graph, Literal, Namespace, URIRef @@ -50,7 +51,8 @@ """ assert jsonRepr is None or isinstance(jsonRepr, str), repr(jsonRepr) self._jsonRepr = jsonRepr - self._addQuads, self._delQuads = addQuads, delQuads + self._addQuads = list(addQuads) if addQuads is not None else None + self._delQuads = list(delQuads) if delQuads is not None else None self._addGraph, self._delGraph = addGraph, delGraph if self._jsonRepr is not None: @@ -60,6 +62,14 @@ if 'senderUpdateUri' in body: self.senderUpdateUri = URIRef(body['senderUpdateUri']) + self._validateDecimals() + + def _validateDecimals(self): + for q in itertools.chain(self.addQuads, self.delQuads): + if isinstance(q[2], Literal): + if cast(Literal, q[2]).datatype in [XSD['double'], XSD['float']]: + raise ValueError(f'fix creation of quad {q} to use xsd:decimal, or comparisons will fail') + def __str__(self): def shorten(n): diff -r d195a5f50137 -r a47c8224e97f rdfdb/patch_test.py --- a/rdfdb/patch_test.py Mon May 29 16:14:17 2023 -0700 +++ b/rdfdb/patch_test.py Mon May 29 16:15:46 2023 -0700 @@ -56,3 +56,8 @@ def testMultiContextPatchFailsToReturnContext(self): p = Patch(addQuads=[stmt1[:3] + (U('http://ctx1'),), stmt1[:3] + (U('http://ctx2'),)]) self.assertRaises(ValueError, p.getContext) + +class TestPatchDoesntConsumeIterators: + def test(self): + p = Patch(addQuads=iter(stmt1)) + assert not p.isEmpty() \ No newline at end of file