1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Work around race when creating ClientPrefs

Closes #220
This commit is contained in:
Alban Féron 2021-09-11 16:21:04 +02:00
parent aea8ebeb13
commit e6e20d1669
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -11,7 +11,7 @@ import binascii
import uuid import uuid
from flask import request from flask import request
from flask import Blueprint from flask import Blueprint
from pony.orm import ObjectNotFound from pony.orm import ObjectNotFound, TransactionIntegrityError
from pony.orm import commit from pony.orm import commit
from ..db import ClientPrefs, Folder from ..db import ClientPrefs, Folder
@ -83,8 +83,15 @@ def get_client_prefs():
try: try:
request.client = ClientPrefs[request.user, client] request.client = ClientPrefs[request.user, client]
except ObjectNotFound: except ObjectNotFound:
try:
request.client = ClientPrefs(user=request.user, client_name=client) request.client = ClientPrefs(user=request.user, client_name=client)
commit() commit()
except TransactionIntegrityError:
# We might have hit a race condition here, another request already created
# the ClientPrefs. Issue #220
# Reload the user or Pony will complain about different transactions
request.user = UserManager.get(request.user.id)
request.client = ClientPrefs[request.user, client]
def get_entity(cls, param="id"): def get_entity(cls, param="id"):