Opened 6 years ago

Last modified 5 months ago

#2423 reopened defect

sqlalchemy IntegrityError: insert on table "buildsets" violates foreign key constraint "buildsets_sourcestampid_fkey"

Reported by: jaredgrubb Owned by:
Priority: major Milestone: 0.8.x
Version: 0.8.12 Keywords: eight
Cc: boris.savelev@…

Description (last modified by tardyp)

Got a couple of these today. Retrying the build a couple times fixed it, so I think it's a race condition.

I'm currently running off revision: v0.8.7p1-216-g315c66b (which is on master branch)

Change History (6)

comment:1 Changed 6 years ago by jaredgrubb

Here's the exception details; it's not letting me paste the whole thing in (it complains my content looks like spam grr)

    sqlalchemy.exc.IntegrityError: (IntegrityError) insert or update on table "buildsets" violates foreign key constraint "buildsets_sourcestampid_fkey"
    DETAIL:  Key (sourcestampsetid)=(1951) is not present in table "sourcestamps".
     'INSERT INTO buildsets (external_idstring, reason, submitted_at, complete, complete_at, results, sourcestampsetid) VALUES (%(external_idstring)s, %(reason)s, %(submitted_at)s, %(complete)s, %(complete_at)s, %(results)s, %(sourcestampsetid)s) RETURNING buildsets.id' {'complete_at': None, 'submitted_at': 1357595917.495083, 'results': -1, 'reason': 'Triggerable(Trigger-Update-AllSlaves)', 'external_idstring': None, 'sourcestampsetid': 1951, 'complete': 0}

comment:2 Changed 6 years ago by dustin

  • Milestone changed from undecided to 0.9.0
  • Resolution set to fixed
  • Status changed from new to closed

Stupid Akismet. If you link to a pastebin I can edit the Trac comment afterward and add the pastebin comments. Next time..

I'm assuming this is using Postgres, based on the error message.

Oh! I know what this is. In 'nine' I noticed that the way the migration to sourcestampsets works, buildsets ends up with a foreign key reference from buildsets.sourcestampid to *both* sourcestamps.id *and* sourcestampsets.id. I've fixed this in the 9/sourcestamps branch (as part of a much larger refactor).

For your case, I suspect you could simply drop the bogus buildset_sourcestamps_fkey. IIRC that looks like

ALTER TABLE buildsets drop foreign key buildset_sourcestamps_fkey

I don't think this is worth its own migration script (although I may change my mind if others run into the same thing).

comment:3 Changed 6 years ago by jaredgrubb

FWIW, the command is actually:

ALTER TABLE buildsets DROP CONSTRAINT buildsets_sourcestampid_fkey;

I've run that command and will see if that fixes the issue. I continue to hit this once every few weeks .. hard to say if it's fixed, but I'll know it's NOT if I see it again!

comment:4 Changed 3 years ago by Ben

  • Keywords eight added
  • Milestone changed from 0.9.0 to 0.8.x
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from master to 0.8.10

We just had this problem on a rather fresh install, so I'd suggest as long as eight is out, we need a fix there.

comment:5 Changed 19 months ago by bsavelev

  • Cc boris.savelev@… added
  • Version changed from 0.8.10 to 0.8.12

same on 0.8.12 drop CONSTRAINT create another problem here:

if res.rowcount != 1:
    raise KeyError

https://github.com/buildbot/buildbot/blob/eight/master/buildbot/db/buildsets.py#L122

Last edited 5 months ago by bsavelev (previous) (diff)

comment:6 Changed 19 months ago by tardyp

  • Description modified (diff)

Note that we are looking for a maintainer for the eight branch. If you really need a fix, please consider upgrade to nine

Note: See TracTickets for help on using tickets.