summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Callaghan <dcallagh@redhat.com>2011-11-15 16:27:35 +1000
committerDan Callaghan <dcallagh@redhat.com>2011-11-15 16:27:35 +1000
commit9f4d74d180f79c3f9bb3fbb765707d7f57ff3996 (patch)
treed11305f3b3f41a12b2882c7860086d004d61f944
parented24690c5bf0e3604ec0746ddbf701f68de9fb8f (diff)
Revert fix for bug 752869: "race condition when adding distros"
This reverts commit fb06ce0d820c1e3a57fc1e64969f4577e6c3e2aa.
-rw-r--r--Server/bkr/server/labcontroller.py9
-rw-r--r--Server/bkr/server/model.py14
2 files changed, 10 insertions, 13 deletions
diff --git a/Server/bkr/server/labcontroller.py b/Server/bkr/server/labcontroller.py
index 47e4df9..028a3b1 100644
--- a/Server/bkr/server/labcontroller.py
+++ b/Server/bkr/server/labcontroller.py
@@ -144,9 +144,12 @@ class LabControllers(RPCRoot):
def _addDistro(self, lab_controller, new_distro):
arches = []
- # Look up the distro by the install name
- distro = Distro.lazy_create(install_name=new_distro['name'])
- distro.name = new_distro['treename']
+ # Try and look up the distro by the install name
+ try:
+ distro = Distro.by_install_name(new_distro['name'])
+ except InvalidRequestError:
+ distro = Distro(new_distro['name'])
+ distro.name = new_distro['treename']
# All the arches this distro's osmajor applies to
if 'arches' in new_distro:
diff --git a/Server/bkr/server/model.py b/Server/bkr/server/model.py
index e413043..565173b 100644
--- a/Server/bkr/server/model.py
+++ b/Server/bkr/server/model.py
@@ -15,7 +15,7 @@ from sqlalchemy.orm import relation, backref, synonym, dynamic_loader, \
from sqlalchemy.orm.interfaces import AttributeExtension
from sqlalchemy.sql import exists
from sqlalchemy.sql.expression import join
-from sqlalchemy.exceptions import InvalidRequestError, IntegrityError
+from sqlalchemy.exceptions import InvalidRequestError
from sqlalchemy.orm.exc import NoResultFound
from identity import LdapSqlAlchemyIdentityProvider
from cobbler_utils import consolidate, string_to_hash
@@ -1133,15 +1133,9 @@ class MappedObject(object):
try:
item = cls.query.filter_by(**kwargs).one()
except NoResultFound:
- try:
- item = cls(**kwargs)
- session.add(item)
- session.flush([item])
- # small race condition where its been created in between
- # us querying it.
- except IntegrityError:
- # if we fail again then let the traceback propagate
- item = cls.query.filter_by(**kwargs).one()
+ item = cls(**kwargs)
+ session.add(item)
+ session.flush([item])
return item
def __init__(self, **kwargs):