Unequal schemas in record assignment

I am writing a source catalog by copy a source (src) from a mergedDet SourceCatalog (sources) into a catalog for each band (template_catalogs[band]).

For sources with a single detection I use

tsrc = template_catalogs[band].addNew()
tsrc.set(self.runtimeKey, 0)

but for deblended sources I use

tsrc = template_catalogs[band].addNew()
tsrc.set("id", parentId)
tsrc.set(self.runtimeKey, runtime)

to add the parents (I update the footprints later) and

child = template_catalogs[band].addNew()
child.assign(heavy.getPeaks()[0], self.peakSchemaMapper)

to add the children.

I checked the schema of the SourceCatalog against the schema for each record in a template_catalogs for a given band (and they match), but when I try to write the catalog to a file with catalogs["I"].writeFits(os.path.join(savePath, 'templates_I.fits')), I get the error:

LogicError                                Traceback (most recent call last)
<ipython-input-17-74b368735cd4> in <module>()
  1 savePath = "/home/fred3m/lsst"
----> 2 catalogs["I"].writeFits(os.path.join(savePath, 'templates_I.fits'))

  File "src/table/BaseRecord.cc", line 75, in void lsst::afw::table::BaseRecord::assign(const lsst::afw::table::BaseRecord&)
Unequal schemas in record assignment. {0}
lsst::pex::exceptions::LogicError: 'Unequal schemas in record assignment.'

Does anyone have any ideas about what is happening?

If the schemas for all of the SourceCatalogs match, the problem may be in the schemas of the PeakCatalogs in the Footprints, so I think the first step in debugging this would be to check whether those all match.

After that, if you can get to the point the exception is thrown in C++ in a debugger and get the full traceback, that’d be helpful. I don’t see anything wrong with what you’ve posted so far, and a schema-mismatch error when writing isn’t something I’ve seen before.

Ok, thanks to @natelust I was able to diagnose the problem. Apparently afw::table::Catalogs do not check the schema when a recorded is being appended with the append method. So the schema of the catalog and the schema of the records were different, which was only checked when attempting to write the Schema to a file.

Ticket DM-12506 has been opened to fix the bug in afw table.