diff --git a/improc/alignment.py b/improc/alignment.py index 15f62066..7408647a 100644 --- a/improc/alignment.py +++ b/improc/alignment.py @@ -11,7 +11,6 @@ import astropy.wcs.utils from util import ldac -from util.config import Config from util.exceptions import SubprocessFailure from util.util import read_fits_image, save_fits_image_file from util.logger import SCLogger @@ -28,7 +27,6 @@ from pipeline.data_store import DataStore from pipeline.parameters import Parameters from pipeline.detection import Detector -from pipeline.photo_cal import PhotCalibrator from improc.bitmask_tools import dilate_bitflag diff --git a/models/base.py b/models/base.py index 69876fc5..e66e020f 100644 --- a/models/base.py +++ b/models/base.py @@ -543,8 +543,23 @@ def copy(self): """Make a new instance of this object, with all column-based attributed (shallow) copied. """ new = self.__class__() for key in sa.inspect(self).mapper.columns.keys(): - value = getattr(self, key) - setattr(new, key, value) + # HACK ALERT + # I was getting a sqlalchemy.orm.exc.DetachedInstanceError + # trying to copy a zeropoint deep inside alignment, and it + # was on the line value = getattr(self, key) trying to load + # the "modified" colum. Rather than trying to figure out WTF + # is going on with SQLAlchmey *this* time, I just decided that + # when we copy an object, we don't copy the modified field, + # so that I could move on with life. + # (This isn't necessarily terrible; one could make the argument + # that the modified field of the new object *should* be now(), + # which is the default. The real worry is that it's yet another + # mysterious SQLAlchemy thing, which just happened to be this field + # this time around. As long as we're tied to the albatross that is + # SQLAlchemy, these kinds of things are going to keep happening.) + if key != 'modified': + value = getattr(self, key) + setattr(new, key, value) return new diff --git a/pipeline/data_store.py b/pipeline/data_store.py index 8f3d6d65..f5f83270 100644 --- a/pipeline/data_store.py +++ b/pipeline/data_store.py @@ -1501,6 +1501,12 @@ def save_and_commit(self, exists_ok=False, overwrite=True, no_archive=False, self.reference = self.reference.merge_all(session) self.sub_image.ref_image = self.reference.image self.sub_image.new_image = self.image # update with the now-merged image + # Make sure that the sub_image's image upstreams are the things that are now properly + # merged with the session. (OMG sqlalchemy is a nightmare) + if ( self.sub_image.new_image.mjd < self.sub_image.ref_image.mjd ): + self.sub_image.upstreams = [ self.sub_image.new_image, self.sub_image.ref_image ] + else: + self.sub_image.upstreams = [ self.sub_image.ref_image, self.sub_image.new_image ] self.sub_image = self.sub_image.merge_all(session) # merges the upstream_images and downstream products self.sub_image.ref_image.id = self.sub_image.ref_image_id self.detections = self.sub_image.sources