Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run(self):


setup(name='citrine',
version='0.12.0',
version='0.12.1',
url='http://github.com/CitrineInformatics/citrine-python',
description='Python library for the Citrine Platform',
author='Andrew Millspaugh',
Expand Down
26 changes: 9 additions & 17 deletions src/citrine/seeding/find_or_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@ def find_collection(collection, name):

Returns it, or if not found, returns None
"""
i = 1
per_page = 100
result = None
while True:
collection_list = list(collection.list(page=i, per_page=per_page))
if len(collection_list) == 0:
break
matching_resources = [resource for resource in collection_list if resource.name == name]
if len(matching_resources) > 0:
if result or len(matching_resources) > 1:
raise ValueError("Found multiple collections with name {}".format(name))
else:
result = matching_resources.pop()
i += 1

if result:
collection_list = collection.list()
matching_resources = [resource for resource in collection_list if resource.name == name]
if len(matching_resources) > 1:
raise ValueError("Found multiple collections with name '{}'".format(name))
if len(matching_resources) == 1:
result = matching_resources.pop()
print('Found existing: {}'.format(result))
return result
return result
else:
return None


def get_by_name_or_create(collection, name, default_provider):
Expand Down