Skip to content

Commit 5817dd9

Browse files
Merge pull request #22 from christophfink/duplicate-tags
fix race conditions around tags (duplicate keys)
2 parents f85ce7c + 9193a2e commit 5817dd9

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- **0.3.1** (2025-04-16):
2+
- fix race conditions around tags (duplicate keys)
3+
14
- **0.3.0** (2025-04-15):
25
- now collecting more data: tags, license, geo-accuracy
36
- re-downloading these data for existing records

src/flickrhistory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
except ImportError:
1616
pass
1717

18-
__version__ = "0.3.0.post1"
18+
__version__ = "0.3.1"

src/flickrhistory/database/photo_saver.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import datetime
99

10+
import sqlalchemy
11+
1012
from .models import License, Photo, Tag
1113
from .session import Session
1214
from .user_saver import UserSaver
@@ -108,10 +110,12 @@ def save(self, data):
108110
photo.update(**photo_data)
109111

110112
photo.tags = []
111-
for tag in tags:
112-
tag = session.merge(session.get(Tag, tag) or Tag(tag=tag))
113-
if tag not in photo.tags:
114-
photo.tags.append(tag)
113+
for tag in set(tags):
114+
try:
115+
with session.begin_nested():
116+
photo.tags.append(session.merge(Tag(tag=tag)))
117+
except sqlalchemy.exc.IntegrityError:
118+
photo.tags.append(session.get(Tag, tag))
115119

116120
license = session.merge(
117121
session.get(License, license) or License(id=license)

0 commit comments

Comments
 (0)