From 15a69ac872de4570eb00ff6384fda9a9ba826da8 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 14 Jan 2015 12:56:06 -0500 Subject: [PATCH] Change robot deletions to set the performer to null, rather than attempting to delete the rows from the large log entries table --- data/database.py | 11 ++++++++--- test/test_api_usage.py | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/data/database.py b/data/database.py index b49c8a594..84d5cd879 100644 --- a/data/database.py +++ b/data/database.py @@ -122,8 +122,9 @@ def close_db_filter(_): class QuayUserField(ForeignKeyField): - def __init__(self, allows_robots=False, *args, **kwargs): + def __init__(self, allows_robots=False, robot_null_delete=False, *args, **kwargs): self.allows_robots = allows_robots + self.robot_null_delete = robot_null_delete if not 'rel_model' in kwargs: kwargs['rel_model'] = User @@ -157,7 +158,11 @@ class User(BaseModel): for query, fk in self.dependencies(search_nullable=True): if isinstance(fk, QuayUserField) and fk.allows_robots: model = fk.model_class - model.delete().where(query).execute() + + if fk.robot_null_delete: + model.update(**{fk.name: None}).where(query).execute() + else: + model.delete().where(query).execute() # Delete the instance itself. super(User, self).delete_instance(recursive=False, delete_nullable=False) @@ -459,7 +464,7 @@ class LogEntry(BaseModel): kind = ForeignKeyField(LogEntryKind, index=True) account = QuayUserField(index=True, related_name='account') performer = QuayUserField(allows_robots=True, index=True, null=True, - related_name='performer') + related_name='performer', robot_null_delete=True) repository = ForeignKeyField(Repository, index=True, null=True) datetime = DateTimeField(default=datetime.now, index=True) ip = CharField(null=True) diff --git a/test/test_api_usage.py b/test/test_api_usage.py index ff7ab5f10..27384daa8 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -1965,6 +1965,9 @@ class TestOrgRobots(ApiTestCase): pull_robot = model.get_user(membername) model.create_build_trigger(repo, 'fakeservice', 'sometoken', user, pull_robot=pull_robot) + # Add some log entries for the robot. + model.log_action('pull_repo', ORGANIZATION, performer=pull_robot, repository=repo) + # Delete the robot and verify it works. self.deleteResponse(OrgRobot, params=dict(orgname=ORGANIZATION, robot_shortname='bender'))