Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
meitros committed Jun 16, 2015
1 parent 055108c commit 8ba1747
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion changes/api/build_index.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion changes/jobs/import_repo.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion changes/jobs/sync_repo.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions changes/vcs/base.py
Expand Up @@ -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)
8 changes: 3 additions & 5 deletions stream_data.py
Expand Up @@ -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.
"""
Expand All @@ -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)


Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/changes/vcs/test_base.py
Expand Up @@ -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

Expand Down

0 comments on commit 8ba1747

Please sign in to comment.