# HG changeset patch # User Sascha Wilde # Date 1564680103 -7200 # Node ID eb08fbe330745151f7e7a5469471ebaae4fc7284 # Parent ec8438712447ff3b91206b4e784593c0fbb9f095 Fixed bn-import: never write tracking info to the db if import fails. diff -r ec8438712447 -r eb08fbe33074 pkg/imports/bn.go --- a/pkg/imports/bn.go Thu Aug 01 19:12:47 2019 +0200 +++ b/pkg/imports/bn.go Thu Aug 01 19:21:43 2019 +0200 @@ -523,20 +523,10 @@ "with intersecting validity already exists: "+ "REPLACING all of them!", bn.Bottleneck_id) } - - for _, oldID := range oldBnIds { - // It is possible, that two new bottlenecks intersect with the - // same old noe, therefor we have to handle duplicates in - // oldBnIds. - if !seenOldBnIds[oldID] { - if _, err := tx.StmtContext(ctx, bs.track).ExecContext( - ctx, importID, "waterway.bottlenecks", oldID, true, - ); err != nil { - return err - } - seenOldBnIds[oldID] = true - } - } + // We write the actual tracking information for deletion of superseded + // bottlenecks later to the databs -- AFTER the new bottleneck was + // created successfully. That way, we don't change the database, when + // an error arises during inserting the new data. var bnIds []int64 // Add new BN data: @@ -598,7 +588,21 @@ return nil } - // Only add new BN data to tracking for staging review. + // Now that adding BNs to staging was successful, write import tracking + // information to database: + for _, oldID := range oldBnIds { + // It is possible, that two new bottlenecks intersect with the + // same old noe, therefor we have to handle duplicates in + // oldBnIds. + if !seenOldBnIds[oldID] { + if _, err := tx.StmtContext(ctx, bs.track).ExecContext( + ctx, importID, "waterway.bottlenecks", oldID, true, + ); err != nil { + return err + } + seenOldBnIds[oldID] = true + } + } for _, nid := range bnIds { if _, err := tx.StmtContext(ctx, bs.track).ExecContext( ctx, importID, "waterway.bottlenecks", nid, false,