Skip to content
Snippets Groups Projects
Verified Commit fb629eb3 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

Merge remote-tracking branch 'origin/dev' into f-more-caching

parents e9f222e8 c7885044
No related branches found
No related tags found
1 merge request!160STY: styling
Pipeline #47144 passed with warnings
......@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ###
* 'transform' sections can be added to a CFood to apply functions to values stored in variables.
* default transform functions: submatch, split and replace.
* `*` can now be used as a wildcard in the identifiables parameter file to denote
that any Record may reference the identified one.
### Changed ###
- If the `parents` key is used in a cfood at a lower level for a Record that
......
......@@ -936,7 +936,7 @@ class Crawler(object):
if isinstance(el, str):
try:
# the get_entity function will raise an error if not unique
propval.append(Crawler._get_property_id_for_datatype(rtname=prop.datatype,
propval.append(Crawler._get_property_id_for_datatype(rtname=dt,
name=el))
except (db.EmptyUniqueQueryError, db.QueryNotUniqueError):
logger.error(
......
......@@ -226,18 +226,25 @@ identifiabel, identifiable and identified record) for a Record.
# separate class too
if prop.name.lower() == "is_referenced_by":
for givenrt in prop.value:
rt_and_children = get_children_of_rt(givenrt)
found = False
for rtname in rt_and_children:
if (id(record) in referencing_entities
and rtname in referencing_entities[id(record)]):
identifiable_backrefs.extend(
referencing_entities[id(record)][rtname])
if givenrt == "*":
if id(record) not in referencing_entities:
continue
for rt, rec in referencing_entities[id(record)].items():
identifiable_backrefs.extend(rec)
found = True
else:
rt_and_children = get_children_of_rt(givenrt)
for rtname in rt_and_children:
if (id(record) in referencing_entities
and (rtname in referencing_entities[id(record)])):
identifiable_backrefs.extend(
referencing_entities[id(record)][rtname])
found = True
if not found:
# TODO: is this the appropriate error?
raise NotImplementedError(
f"The following record is missing an identifying property:"
f"The following record is missing an identifying property:\n"
f"RECORD\n{record}\nIdentifying PROPERTY\n{prop.name}"
)
continue
......
......@@ -85,7 +85,9 @@ we can check whether a Record with the parent "Project" is referencing the "Expe
Record. If that is the case, this reference is part of the identifiable for the "Experiment"
Record. Note, that if there are multiple Records with the appropriate parent (e.g.
multiple "Project" Records in the above example) it will be required that all of them
reference the object to be identified.
reference the object to be identified. You can also use the wildcard "*" as
RecordType name in the configuration which will only require, that ANY Record
references the Record at hand.
Identified Records
......
......@@ -133,6 +133,22 @@ def test_non_default_name():
assert identifiable.name is None
def test_wildcard_ref():
ident = CaosDBIdentifiableAdapter()
ident.register_identifiable(
"Person", db.RecordType()
.add_parent(name="Person")
.add_property(name="is_referenced_by", value=["*"]))
rec = (db.Record(name="don't touch it").add_parent("Person")
.add_property(name="last_name", value='Tom'))
identifiable = ident.get_identifiable(rec,
referencing_entities={
id(rec):
{'A': [db.Record(id=1).add_parent("A")]}}
)
assert identifiable.backrefs[0].id == 1
def test_convert_value():
# test that string representation of objects stay unchanged. No stripping or so.
class A():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment