Bug 825913 - distro import fails if distro row already exists with incorrect osversion
distro import fails if distro row already exists with incorrect osversion
Product: Beaker
Classification: Community
Component: scheduler (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified (vote)
: 0.9.0
: ---
Assigned To: Dan Callaghan
Depends On:
  Show dependency treegraph
Reported: 2012-05-29 00:22 EDT by Dan Callaghan
Modified: 2012-06-26 02:40 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2012-06-26 02:40:20 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Dan Callaghan 2012-05-29 00:22:01 EDT
When importing a distro, if the distro row already exists but refers to a different osversion than the one being sent in the import data, then the import will fail:

2012-05-29 14:11:13,684 bkr.server.xmlrpccontroller DEBUG Time: 0:00:00.037483 labcontrollers.add_distro_tree ({'osma
jor': 'RedHatEnterpriseLinux3', 'name': 'RH
2012-05-29 14:11:14,041 bkr.server.xmlrpccontroller ERROR Error handling XML-RPC method
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/bkr/server/xmlrpccontroller.py", line 54, in RPC2
    response = self.process_rpc(method,params)
  File "/usr/lib/python2.6/site-packages/bkr/server/xmlrpccontroller.py", line 43, in process_rpc
    response = obj(*params)
  File "<string>", line 3, in add_distro_tree
  File "/usr/lib/python2.6/site-packages/turbogears/identity/conditions.py", line 249, in require
    return fn(self, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/bkr/server/labcontroller.py", line 128, in add_distro_tree
    distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)
  File "/usr/lib/python2.6/site-packages/bkr/server/model.py", line 1259, in lazy_create
    item = cls.query.filter_by(**kwargs).one()
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 1684, in one
    raise orm_exc.NoResultFound("No row was found for one()")
NoResultFound: No row was found for one()

Ideally this should never happen, but it might if the distro was previously imported with wrong .treeinfo or using an old import script that got things wrong.
Comment 1 Dan Callaghan 2012-05-29 00:31:09 EDT
The problem stems from this line:

    distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)

Distro is unique only on name, but osversion_id is not NULLable so we have to pass that in here as well in case the row is created. This bug happens if the osversion we are passing in is not the same as the osversion on the existing row, so when lazy_create tries to query it back, nothing matches.

The lazy_create method needs some way to distinguish unique columns from creation columns. That might be difficult to do in the general case, but I think distro is the only table in this boat so maybe we can just override Distro.lazy_create to handle it.

Or we could make distro.osversion_id NULLable and update it after calling lazy_create. But that seems a bit dodgy.
Comment 2 Dan Callaghan 2012-05-29 01:46:13 EDT
On Gerrit: http://gerrit.beaker-project.org/1090
Comment 4 Dan Callaghan 2012-06-26 02:40:20 EDT
Beaker 0.9.0 has been released.

Note You need to log in before you can comment on or make changes to this bug.