time-link / timelink-py

Timelink Python Package
MIT License
3 stars 0 forks source link

db.get_person, get_entity and others should have a session param #44

Closed joaquimrcarvalho closed 3 weeks ago

joaquimrcarvalho commented 3 months ago

Description

TimelinkNotebook exposes TimelinkDatabase methods get_person get_entity but these return unbound instances that need to be attached to session to be used in most use cases:

What I Did


p = tlnb.db.get_person(id)
print(p.to_kleio())

---

---------------------------------------------------------------------------
DetachedInstanceError                     Traceback (most recent call last)
Cell In[13], [line 2](vscode-notebook-cell:?execution_count=13&line=2)
      [1](vscode-notebook-cell:?execution_count=13&line=1) p = tlnb.db.get_person(id)
----> [2](vscode-notebook-cell:?execution_count=13&line=2) print(p.to_kleio())
DetachedInstanceError: Parent instance <Person at 0x14007f250> is not bound to a Session; lazy load operation of attribute 'contains' cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)

It should be possible to do

with tlnb.db.session() as session:

  p = tlnb.db.get_person(id)
  print(p.to_kleio())