Skip to content

Commit

Permalink
Merge pull request #1007 from PrefectHQ/storage-update
Browse files Browse the repository at this point in the history
Add fix for calling serialize twice
  • Loading branch information
cicdw authored May 7, 2019
2 parents 329c05a + 5c01b90 commit c39aa11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/prefect/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def serialize(self, build: bool = False) -> dict:
if build:
if not self.storage:
raise ValueError("This flow has no storage to build")
if self not in self.storage:
if self.name not in self.storage:
self.storage.add_flow(self)
storage = self.storage.build() # type: Optional[Storage]
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/core/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,14 @@ def test_serialize_adds_flow_to_storage_if_build(self):
s_build = f.serialize(build=True)
assert f.name in f.storage

def test_serialize_can_be_called_twice(self):
f = Flow(name="test", storage=prefect.environments.storage.Memory())
s_no_build = f.serialize()
assert f.name not in f.storage

f.serialize(build=True)
f.serialize(build=True)

def test_serialize_fails_with_no_storage(self):
f = Flow(name="test")
with pytest.raises(ValueError):
Expand Down

0 comments on commit c39aa11

Please sign in to comment.