Bug 825913 - distro import fails if distro row already exists with incorrect osversion
Summary: distro import fails if distro row already exists with incorrect osversion
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Beaker
Classification: Retired
Component: scheduler
Version: 0.9
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Dan Callaghan
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-05-29 04:22 UTC by Dan Callaghan
Modified: 2019-05-22 13:42 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-26 06:40:20 UTC
Embargoed:


Attachments (Terms of Use)

Description Dan Callaghan 2012-05-29 04:22:01 UTC
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 04:31:09 UTC
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 05:46:13 UTC
On Gerrit: http://gerrit.beaker-project.org/1090

Comment 4 Dan Callaghan 2012-06-26 06:40:20 UTC
Beaker 0.9.0 has been released.


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