mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-10 04:49:29 +02:00
Remove Tag Unique Constraint Bug (#1519)
This commit is contained in:
parent
97d058b8b2
commit
8688226003
@ -76,17 +76,24 @@ def create_or_add_document_tag_list(
|
||||
raise ValueError("Invalid Document, cannot attach Tags")
|
||||
|
||||
existing_tags_stmt = select(Tag).where(
|
||||
Tag.tag_key == tag_key, Tag.tag_value.in_(tag_values), Tag.source == source
|
||||
Tag.tag_key == tag_key,
|
||||
Tag.tag_value.in_(valid_tag_values),
|
||||
Tag.source == source,
|
||||
)
|
||||
existing_tags = list(db_session.execute(existing_tags_stmt).scalars().all())
|
||||
existing_tag_values = {tag.tag_value for tag in existing_tags}
|
||||
|
||||
new_tags = []
|
||||
for tag_value in tag_values:
|
||||
for tag_value in valid_tag_values:
|
||||
if tag_value not in existing_tag_values:
|
||||
new_tag = Tag(tag_key=tag_key, tag_value=tag_value, source=source)
|
||||
db_session.add(new_tag)
|
||||
new_tags.append(new_tag)
|
||||
existing_tag_values.add(tag_value)
|
||||
|
||||
logger.debug(
|
||||
f"Created new tags: {', '.join([f'{tag.tag_key}:{tag.tag_value}' for tag in new_tags])}"
|
||||
)
|
||||
|
||||
all_tags = existing_tags + new_tags
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user