Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ihatesqlalchemy' into provtag
Browse files Browse the repository at this point in the history
  • Loading branch information
rknop committed Jul 26, 2024
2 parents 714e307 + c08f8a2 commit 39c495b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 28 deletions.
23 changes: 23 additions & 0 deletions models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,31 @@ def merge_all(self, session):
Must provide a session to merge into. Need to commit at the end.
Returns the merged image with all its products on the same session.
DEVELOPER NOTE: changing what gets merged in this function
requires a corresponding change in
pipeline/data_store.py::DataStore.save_and_commit
"""
new_image = self.safe_merge(session=session)

import io
strio = io.StringIO()
strio.write( "In image.merge_all; objects in session:\n" )
if len( session.new ) > 0 :
strio.write( " NEW:\n" )
for obj in session.new:
strio.write( f" {obj}\n" )
if len( session.dirty ) > 0:
strio.write( " DIRTY:\n" )
for obj in session.dirty:
strio.write( f" {obj}\n" )
if len( session.deleted ) > 0:
strio.write( " DELETED:\n" )
for obj in session.deleted:
strio.write( f" {obj}\n" )
SCLogger.debug( strio.getvalue() )

session.flush() # make sure new_image gets an ID

if self.sources is not None:
Expand Down
15 changes: 13 additions & 2 deletions pipeline/data_store.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import warnings
import datetime
import sqlalchemy as sa
Expand Down Expand Up @@ -1379,6 +1380,9 @@ def save_and_commit(self, exists_ok=False, overwrite=True, no_archive=False,
True), as the image headers get "first-look" values, not
necessarily the latest and greatest if we tune either process.
DEVELOPER NOTE: this code has to stay synced properly with
models/image.py::Image.merge_all
Parameters
----------
exists_ok: bool, default False
Expand Down Expand Up @@ -1431,8 +1435,15 @@ def save_and_commit(self, exists_ok=False, overwrite=True, no_archive=False,
if obj is None:
continue

SCLogger.debug( f'save_and_commit considering a {obj.__class__.__name__} with filepath '
f'{obj.filepath if isinstance(obj,FileOnDiskMixin) else "<none>"}' )
strio = io.StringIO()
strio.write( f"save_and_commit of {att} considering a {obj.__class__.__name__}" )
if isinstance( obj, FileOnDiskMixin ):
strio.write( f" with filepath {obj.filepath}" )
elif isinstance( obj, list ):
strio.write( f" of types {[type(i) for i in obj]}" )
SCLogger.debug( strio.getvalue() )
# SCLogger.debug( f'save_and_commit of {att} considering a {obj.__class__.__name__} with filepath '
# f'{obj.filepath if isinstance(obj,FileOnDiskMixin) else "<none>"}' )

if isinstance(obj, FileOnDiskMixin):
mustsave = True
Expand Down
Loading

0 comments on commit 39c495b

Please sign in to comment.