From 6a3f5a925ecc8d730efd2d3acd35ea44389c16c1 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Tue, 23 Dec 2008 10:25:54 -0500 Subject: [PATCH] Eagerload active_datasets for a history rather than activatable_datasets since it throws exceptions in the migration script. --- .../update_database_with_security_libraries.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/update_database/update_database_with_security_libraries.py b/scripts/update_database/update_database_with_security_libraries.py index da60dbcb390..bf8e2aed68b 100644 --- a/scripts/update_database/update_database_with_security_libraries.py +++ b/scripts/update_database/update_database_with_security_libraries.py @@ -170,6 +170,7 @@ def main(): default_user_action = security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS.action for user in app.model.User.query().all(): + print print "################" print "Setting up user %s." % user.email private_role = security_agent.get_private_user_role( user ) @@ -187,12 +188,14 @@ def main(): dup = app.model.DefaultUserPermissions( user, default_user_action, private_role ) dup.flush() # Set DefaultHistoryPermissions on all of the user's active histories and associated datasets + # TODO: fix mapping for history.activatable_datasets so it doesn't throw an exception on the + # following query when eagerloading activatable_datasets. Fix all of the queries below that + # call history.active_datasets to be history.activatable_datasets when this works. histories = app.model.History.filter( and_( app.model.History.table.c.user_id==user.id, - app.model.History.table.purged==False ) ) \ - .options( eagerload( 'activatable_datasets' ) ).all() + app.model.History.table.c.purged==False ) ) \ + .options( eagerload( 'active_datasets' ) ).all() print "Setting DefaultHistoryPermissions for %d un-purged histories associated with %s" % ( len( histories ), user.email ) for history in histories: - print "Working on history %d" % history.id # Delete all of the current default permissions for the history for dhp in history.default_permissions: dhp.delete() @@ -200,11 +203,10 @@ def main(): # Add the new default permissions for the history dhp = app.model.DefaultHistoryPermissions( history, default_user_action, private_role ) dhp.flush() - print "Setting ActionDatasetRoleAssociations for %d un-purged datasets in history %d" % ( len( history.activatable_datasets ), history.id ) + print "Setting ActionDatasetRoleAssociations for %d un-purged datasets in history %d" % ( len( history.active_datasets ), history.id ) # Set the permissions on the current history's datasets that are not purged - for hda in history.activatable_datasets: + for hda in history.active_datasets: dataset = hda.dataset - print "Working on dataset %d" % dataset.id if dataset.library_associations: # Don't change permissions on a dataset associated with a library continue