Skip to content

Commit

Permalink
small
Browse files Browse the repository at this point in the history
  • Loading branch information
rknop committed Jul 15, 2024
1 parent b90dcd6 commit 6c6edf5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 0 additions & 2 deletions improc/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
19 changes: 17 additions & 2 deletions models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions pipeline/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c6edf5

Please sign in to comment.