Skip to content

Commit 2d762cb

Browse files
committed
fix mixed data in empty text field
1 parent 60bf0f2 commit 2d762cb

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import Enum
55
from typing import Any, TYPE_CHECKING
66

7-
from sqlalchemy import ForeignKey, ForeignKeyConstraint
7+
from sqlalchemy import ForeignKey
88
from sqlalchemy.orm import Mapped, mapped_column, relationship, declared_attr
99

1010
from .db import Base
@@ -39,7 +39,7 @@ def entry(cls) -> Mapped[Entry]:
3939

4040
@declared_attr
4141
def position(cls) -> Mapped[int]:
42-
return mapped_column()
42+
return mapped_column(default=0)
4343

4444
def __hash__(self):
4545
return hash(self.__key())
@@ -66,13 +66,6 @@ def __eq__(self, value) -> bool:
6666

6767
class TextField(BaseField):
6868
__tablename__ = "text_fields"
69-
# constrain for combination of: entry_id, type_key and position
70-
__table_args__ = (
71-
ForeignKeyConstraint(
72-
["entry_id", "type_key", "position"],
73-
["text_fields.entry_id", "text_fields.type_key", "text_fields.position"],
74-
),
75-
)
7669

7770
value: Mapped[str | None]
7871

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import shutil
33
from os import makedirs
44
from pathlib import Path
5-
from random import randint
65
from typing import Iterator, Any, Type
76
from uuid import uuid4
87

@@ -632,7 +631,6 @@ def add_entry_field_type(
632631
field_model = TextField(
633632
type_key=field.key,
634633
value=value or "",
635-
position=randint(100, 100_000),
636634
)
637635
elif field.type == FieldTypeEnum.TAGS:
638636
field_model = TagBoxField(
@@ -656,9 +654,6 @@ def add_entry_field_type(
656654
try:
657655
for entry_id in entry_ids:
658656
field_model.entry_id = entry_id
659-
# create random value position to avoid IntegrityError, reordering is below
660-
field_model.position = randint(100, 100_000)
661-
662657
session.add(field_model)
663658
session.flush()
664659

0 commit comments

Comments
 (0)