mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -05:00
Model reprs read only loaded state
A repr runs inside log calls. Reading a relationship or an expired column there runs a query, and on an object whose session is gone it raises DetachedInstanceError instead of logging. Archive's repr also stat'ed its SingleFile file on disk. `wrolpi.common.loaded()` follows attributes through state that is already loaded (primary keys from the identity key) and never runs SQL. Every model repr uses it; with everything loaded the output is unchanged, except Video and Archive now show the FileGroup's primary path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c717f11821
commit
ca1f6dd886
11 changed files with 154 additions and 52 deletions
|
|
@ -9,8 +9,8 @@ from sqlalchemy.orm import Mapped, relationship, Session, joinedload
|
|||
|
||||
from wrolpi import dates
|
||||
from wrolpi.collections import Collection
|
||||
from wrolpi.common import ModelHelper, Base, logger, get_title_from_html, get_wrolpi_config, get_media_directory, \
|
||||
strip_surrogates
|
||||
from wrolpi.common import loaded, ModelHelper, Base, logger, get_title_from_html, get_wrolpi_config, \
|
||||
get_media_directory, strip_surrogates
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.db import serializer
|
||||
from wrolpi.errors import UnknownArchive
|
||||
|
|
@ -60,11 +60,11 @@ class Archive(Base, ModelHelper):
|
|||
return d
|
||||
|
||||
def __repr__(self):
|
||||
domain_name = self.domain if self.collection else None
|
||||
if domain_name:
|
||||
return f'<Archive id={self.id} url={self.file_group.url} singlefile={repr(str(self.singlefile_path))} ' \
|
||||
f'domain={domain_name}>'
|
||||
return f'<Archive id={self.id} url={self.file_group.url} singlefile={repr(str(self.singlefile_path))}>'
|
||||
id_, url = loaded(self, 'id'), loaded(self, 'file_group', 'url')
|
||||
path = repr(str(loaded(self, 'file_group', 'primary_path')))
|
||||
if domain_name := loaded(self, 'collection', 'name'):
|
||||
return f'<Archive id={id_} url={url} path={path} domain={domain_name}>'
|
||||
return f'<Archive id={id_} url={url} path={path}>'
|
||||
|
||||
@property
|
||||
def domain(self) -> str | None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue