Commit 37d535ef authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

metadata: disallow update of the internal meta (should be immutable)

Also we provide a set of internal metadata keys.
parent 67abbb1c3ae4
......@@ -306,20 +306,16 @@ def test_serie_metadata(engine, tsh):
with pytest.raises(AssertionError):
tsh.update_metadata(engine, 'ts-metadata', {'tzaware': True})
tsh.update_metadata(engine, 'ts-metadata', {'tzaware': True}, internal=True)
assert tsh.metadata(engine, 'ts-metadata') == {
'index_dtype': '<M8[ns]',
'index_names': [],
'index_type': 'datetime64[ns]',
'topic': 'banana spot price',
'tzaware': True,
'tzaware': False,
'value_dtype': '<f8',
'value_type': 'float64'
}
# unbreak the serie for the second test pass :o
tsh.update_metadata(engine, 'ts-metadata', initialmeta, internal=True)
def test_changeset_metadata(engine, tsh):
serie = genserie(datetime(2010, 1, 1), 'D', 1, initval=[1])
......
......@@ -28,6 +28,14 @@ class TimeSerie(SeriesServices):
namespace = 'tsh'
schema = None
metadatacache = None
metakeys = {
'tzaware',
'index_type',
'index_names',
'index_dtype',
'value_dtype',
'value_type'
}
registry_map = None
serie_tablename = None
create_lock_id = None
......@@ -120,11 +128,10 @@ class TimeSerie(SeriesServices):
self.metadatacache[seriename] = meta
return meta
def update_metadata(self, cn, seriename, metadata, internal=False):
def update_metadata(self, cn, seriename, metadata):
assert isinstance(metadata, dict)
assert not set(metadata.keys()) & self.metakeys
meta = self.metadata(cn, seriename)
if not internal:
assert set(meta.keys()).intersection(metadata.keys()) == set()
meta.update(metadata)
reg = self.schema.registry
sql = reg.update().where(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment