Skip to content

Commit

Permalink
Ensure that config field is reloaded from index to avoid incorrect re…
Browse files Browse the repository at this point in the history
…computations
  • Loading branch information
frthjf committed Mar 10, 2024
1 parent bc85669 commit 9218031
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<!-- Please add changes under the Unreleased section that reads 'No current changes' otherwise -->

# Unreleased

- Ensure that config field is always reloaded from index to avoid incorrect recomputation

# v4.9.1

- Use text-based link relation by default
Expand Down
17 changes: 10 additions & 7 deletions src/machinable/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def interface_row_factory(cursor, row) -> schema.Interface:
uuid=row[0],
kind=row[1],
module=row[2],
config=None,
config=json.loads(row[3]),
version=json.loads(row[6]),
predicate=json.loads(row[7]),
lineage=json.loads(row[8]),
Expand Down Expand Up @@ -143,10 +143,15 @@ def commit(self, model: schema.Interface) -> bool:
).fetchone():
# already exists
return False
config = copy.deepcopy(model.config or {})
default = config.pop("_default_", {})
version = config.pop("_version_", [])
update = config.pop("_update_", {})
config = copy.deepcopy(model.config)
if config:
default = config.pop("_default_", {})
version = config.pop("_version_", [])
update = config.pop("_update_", {})
else:
default = {}
version = []
update = {}

cur.execute(
"""INSERT INTO 'index' (
Expand Down Expand Up @@ -237,7 +242,6 @@ def find_by_id(self, uuid: str) -> Optional[schema.Interface]:
return None
cur = _db.cursor()
if len(uuid) == 6: # short id
print(f"%{uuid[:2]}-{uuid[2:]}-%")
row = cur.execute(
"""SELECT * FROM 'index' WHERE uuid LIKE ?""",
(f"%{uuid[:2]}-{uuid[2:]}-%",),
Expand Down Expand Up @@ -277,7 +281,6 @@ def find_by_context(self, context: Dict) -> List[schema.Interface]:
)
else:
query = cur.execute("""SELECT * FROM 'index'""")

return [interface_row_factory(cur, row) for row in query.fetchall()]

def find_by_hash(self, context_hash: str) -> List[schema.Interface]:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def test_index_commit(tmp_path):
v.uuid,
"Interface",
None,
*(("{}",) * 3),
"null",
"{}",
"{}",
"[]",
"null",
"[]",
Expand Down

0 comments on commit 9218031

Please sign in to comment.