batches: error when syncing a changeset belonging to a batch change whose owner is deleted
Created by: courier-new
Steps to repro:
- Create a new user/org
- Create a new batch change under this user/org's namespace with at least one changeset
- Publish at least one changeset for this batch change
- Delete the user/org
- Try to sync the changeset/wait for it to sync
Expected behavior:
- A
debug
level message is logged that the changeset will skip syncing due to the batch change belonging to a now-deleted user
Actual behavior:
- An
error
level message is logged, like the following:
"message": "t=2022-07-29T21:41:09+0000 lvl=eror msg=\"Syncing changeset\" err=\"failed to load owning batch change: batch change not found: 105\"",
Our bstore.GetBatchChange
method excludes results where the batch change namespace's user or org has been deleted. This causes us to emit an error message in the syncer when we try to load the batch change for a changeset and cannot find it.
The batch change not existing is indeed a problem we want to look out for and report as an error if encountered. However, the batch change just belonging to a deleted user/org is not a problem, and should not be reported as an error. In order to differentiate these cases in the changeset syncer, we should probably either:
- Not exclude batch changes with a deleted user/org namespace from
bstore.GetBatchChange
, but check for them fromloadBatchChange
instead and log the debug message if we detect the namespace is deleted. - Not exclude batch changes with a deleted user/org namespace from the SQL query used for
bstore.GetBatchChange
, but check and return something likenil, ErrDeletedNamespace
from the method instead, and log the debug message if we get that error from the store.
We'll need to make sure other consumers of the bstore.GetBatchChange
method are able to handle whatever change we make.