From 8ba17479464e22f347ae11d2c0e38e24bcddb500 Mon Sep 17 00:00:00 2001 From: Mihir Kedia Date: Mon, 15 Jun 2015 23:12:49 -0700 Subject: [PATCH] Final needed fix for stream_data.py Summary: revisions were automatically creating source objects, which we then tried to create a second time later. The simple fix is to skip creating source objects from stream_data.py (stream_data.py sometimes creates sources with patches attached, so let's let it create the source.) @ptyl, this is now a working way to get some kind of test data into a local db. (although what you already have more closely resembles production data, so you may not need this) To random future person who may someday read this description: another possible solution is to use session.merge() in our mocking code. Test Plan: stream_data.py with the new flag set to True/False. Only works when False Reviewers: haoyi, vishal, josiah Reviewed By: josiah Subscribers: changesbot, mkedia, ptyl, vishal, tiago Differential Revision: https://tails.corp.dropbox.com/D115339 --- changes/api/build_index.py | 2 +- changes/jobs/import_repo.py | 2 +- changes/jobs/sync_repo.py | 2 +- changes/vcs/base.py | 4 ++-- stream_data.py | 8 +++----- tests/changes/vcs/test_base.py | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/changes/api/build_index.py b/changes/api/build_index.py index 3df4f68e6..0f7039eae 100644 --- a/changes/api/build_index.py +++ b/changes/api/build_index.py @@ -52,7 +52,7 @@ def identify_revision(repository, treeish): # commits so we should really cache the failed lookups raise MissingRevision('Unable to find revision %s' % (treeish,)) - revision, _ = commit.save(repository) + revision, _, __ = commit.save(repository) return revision diff --git a/changes/jobs/import_repo.py b/changes/jobs/import_repo.py index 1921048a5..08f0d2947 100644 --- a/changes/jobs/import_repo.py +++ b/changes/jobs/import_repo.py @@ -40,7 +40,7 @@ def import_repo(repo_id, parent=None): vcs.clone() for commit in vcs.log(parent=parent): - revision, created = commit.save(repo) + revision, created, _ = commit.save(repo) db.session.commit() parent = commit.id diff --git a/changes/jobs/sync_repo.py b/changes/jobs/sync_repo.py index 61eba1f8a..c757f728a 100644 --- a/changes/jobs/sync_repo.py +++ b/changes/jobs/sync_repo.py @@ -52,7 +52,7 @@ def sync_repo(repo_id, continuous=True): while might_have_more: might_have_more = False for commit in vcs.log(parent=parent): - revision, created = commit.save(repo) + revision, created, _ = commit.save(repo) db.session.commit() if not created: break diff --git a/changes/vcs/base.py b/changes/vcs/base.py index 353baee00..990c0c632 100644 --- a/changes/vcs/base.py +++ b/changes/vcs/base.py @@ -220,9 +220,9 @@ def save(self, repository): # we also want to create a source for this item as it's the canonical # representation in the UI - try_create(Source, { + source = try_create(Source, { 'revision_sha': self.id, 'repository': repository, }) - return (revision, created) + return (revision, created, source) diff --git a/stream_data.py b/stream_data.py index 690eaa635..dedbafa58 100755 --- a/stream_data.py +++ b/stream_data.py @@ -182,7 +182,7 @@ def gen(project): return build -def add(project, revision): +def add(project, revision, source): """ Similar to gen, except uses an existing revision for the project :return: A new build that's been saved. """ @@ -196,8 +196,6 @@ def add(project, revision): patch = mock.patch(project) else: patch = None - source = mock.source( - project.repository, revision_sha=revision.sha, patch=patch) return create_new_build(change, source, patch, project) @@ -279,9 +277,9 @@ def simulate_local_repository(): print 'Creating data based on {0} repository in {1}'.format(backend, os.getcwd()) vcs = get_vcs(repository) for lazy_revision in vcs.log(limit=10): - revision, created = lazy_revision.save(repository) + revision, created, source = lazy_revision.save(repository) print ' Created revision {0} in {1}'.format(revision.sha, revision.branches) - build = add(project, revision) + build = add(project, revision, source) print ' Inserted build {0} into {1}'.format(build.id, project.slug) diff --git a/tests/changes/vcs/test_base.py b/tests/changes/vcs/test_base.py index 9d1c3b910..5db69f9e9 100644 --- a/tests/changes/vcs/test_base.py +++ b/tests/changes/vcs/test_base.py @@ -18,7 +18,7 @@ def test_simple(self): parents=['a' * 40, 'b' * 40], ) - revision, created = result.save(repo) + revision, created, _ = result.save(repo) assert created