Skip to content

Commit 4c3e0a3

Browse files
committed
fix: only commit once when creating new library
1 parent ce64fb7 commit 4c3e0a3

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/tagstudio/core/library/alchemy/library.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def create_sqlite_library(
452452

453453
# TODO: are all of these commits necessary?
454454
session.add_all(namespaces)
455-
session.commit()
455+
session.flush()
456456

457457
# Add default tag colors.
458458
tag_colors: list[TagColorGroup] = default_color_groups.standard()
@@ -463,21 +463,21 @@ def create_sqlite_library(
463463
tag_colors += default_color_groups.neon()
464464

465465
session.add_all(tag_colors)
466-
session.commit()
466+
session.flush()
467467

468468
# Add default tags.
469469
session.add_all(get_default_tags())
470-
session.commit()
470+
session.flush()
471471

472472
# Add default field templates
473473
for template in get_default_field_templates():
474474
session.add(template)
475-
session.commit()
475+
session.flush()
476476

477477
# Ensure version rows are present
478478
session.add(Version(key=DB_VERSION_INITIAL_KEY, value=DB_VERSION))
479479
session.add(Version(key=DB_VERSION_CURRENT_KEY, value=DB_VERSION))
480-
session.commit()
480+
session.flush()
481481

482482
# add folder for current path
483483
folder = Folder(
@@ -486,7 +486,7 @@ def create_sqlite_library(
486486
)
487487
session.add(folder)
488488
session.expunge(folder)
489-
session.commit()
489+
session.flush()
490490
self.folder = folder
491491

492492
# Generate default .ts_ignore file
@@ -512,6 +512,8 @@ def create_sqlite_library(
512512
)
513513
)
514514

515+
session.commit()
516+
515517
# everything is fine, set the library path
516518
self.library_dir = library_dir
517519
return LibraryStatus(success=True, library_path=library_dir)

0 commit comments

Comments
 (0)