Skip to content

Commit

Permalink
attempted fix for import of previously tagged not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
pSpitzner committed Dec 10, 2024
1 parent 39cf568 commit 4496cf4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion backend/beets_flask/database/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Tag(Base):

status: Mapped[str]
kind: Mapped[str]
kind: Mapped[str]
_valid_statuses = [
"dummy",
"pending",
Expand Down
22 changes: 16 additions & 6 deletions backend/beets_flask/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def runPreview(
-------
str: the match url, if we found one, else None.
"""
match_url = None
with db_session() as session:
log.debug(f"Preview task on {tagId}")
log.info(f"Preview task on {tagId}")
bt = Tag.get_by(Tag.id == tagId, session=session)
if bt is None:
raise InvalidUsage(f"Tag {tagId} not found in database")
Expand Down Expand Up @@ -147,6 +148,7 @@ def runPreview(
return None
finally:
bt.updated_at = datetime.now()
session.merge(bt)
session.commit()
update_client_view(
type="tag",
Expand All @@ -163,8 +165,15 @@ def runPreview(
)

log.debug(f"preview done. {bt.status=}, {bt.match_url=}")
match_url = bt.match_url

return bt.match_url
# log what was commited, and use a new session handle to make sure
# it works in other threads.
with db_session() as session:
bt = Tag.get_by(Tag.id == tagId, session=session)
log.debug(f"Tag commited to database: {bt.to_dict() if bt else None}")

return match_url


@job(timeout=600, queue=import_queue, connection=redis_conn)
Expand All @@ -190,11 +199,11 @@ def runImport(
"""
with db_session() as session:
log.debug(f"Import task on {tagId}")
bt = Tag.get_by(Tag.id == tagId)
log.info(f"Import task on {tagId}")
bt = Tag.get_by(Tag.id == tagId, session=session)
if bt is None:
raise InvalidUsage(f"Tag {tagId} not found in database")

log.debug(f"Import task on {bt.to_dict()}")
bt.status = "importing"
bt.updated_at = datetime.now()
session.merge(bt)
Expand Down Expand Up @@ -292,7 +301,7 @@ def AutoImport(tagId: str, callback_url: str | None = None) -> list[str] | None:
List of track paths after import, as strings. (empty if nothing imported)
"""
with db_session() as session:
log.debug(f"AutoImport task on {tagId}")
log.info(f"AutoImport task on {tagId}")
bt = Tag.get_by(Tag.id == tagId, session=session)
if bt is None:
raise InvalidUsage(f"Tag {tagId} not found in database")
Expand Down Expand Up @@ -329,6 +338,7 @@ def AutoImport(tagId: str, callback_url: str | None = None) -> list[str] | None:

def _get_or_gen_match_url(tagId, session: Session) -> str | None:
bt = Tag.get_by(Tag.id == tagId, session=session)
log.debug(f"Getting match url for {bt.to_dict() if bt else None}")
if bt is None:
raise InvalidUsage(f"Tag {tagId} not found in database")
if bt.match_url is not None:
Expand Down
6 changes: 5 additions & 1 deletion backend/beets_flask/routes/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def add_tag():
tags = []
with db_session() as session:
for f in folders:
tag = Tag(album_folder=f, kind=kind)
tag = Tag.get_by(Tag.album_folder == f, session=session)
if tag is not None:
tag.kind = kind
else:
tag = Tag(album_folder=f, kind=kind)
session.merge(tag)
session.commit()
invoker.enqueue(tag.id, session=session)
Expand Down

0 comments on commit 4496cf4

Please sign in to comment.