Ah, sorry, I didn’t grok the question.
The visit and ccd are stored in the deepCoadd. Try something like this:
coaddId = dict(tract=12345, patch='6,7', filter="i")
exp = butler.get("deepCoadd", coaddId, immediate=True)
ccdInputs = exp.getInfo().getCoaddInfo().ccds
visitKey = ccdInputs.schema.find("visit").key
ccdKey = ccdInputs.schema.find("ccd").key
for ccdRecord in ccdInputs:
dataId = dict(visit=ccdRecord.get(visitKey), ccd=ccdRecord.get(ccdKey))
# Work around problem with adding 'tract' to key
dataRefList = list(butler.subset("raw", dataId))
assert(len(dataRefList) == 0)
dataRef = dataRefList.pop()
forced = dataRef.get("forced_src", tract=coaddId['tract'], immediate=True)
I took the bones of this from lsst.pipe.tasks.propagateVisitFlags.
The problem with adding tract to the dataId is mentioned here.