Skip to content
Open
Changes from 3 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
9 changes: 7 additions & 2 deletions surge/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Project(APIResource):

def __init__(self, **kwargs):
super().__init__()
self.__dict__.update(kwargs)
self._update(**kwargs)

if self.id is None:
raise SurgeMissingIDError
Expand All @@ -35,10 +35,15 @@ def __init__(self, **kwargs):
# Convert timestamp str into datetime
self.created_at = dateutil.parser.parse(self.created_at)


def _update(self, **kwargs):
self.__dict__.update(kwargs)

# If the Project has Questions, convert each into a Question object
if hasattr(self, "questions"):
self.questions = self._convert_questions_to_objects(self.questions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project is mutated in-place but the questions are re-instantiated. Is that desirable?
It seems inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not desirable, but it seems relatively difficult to update questions in-place so I'd like to punt on that - see https://github.com/surge-ai/surge-python/blob/main/surge/questions.py#L41



def __str__(self):
return f'<surge.Project#{self.id} name="{self.name}">'

Expand Down Expand Up @@ -397,7 +402,7 @@ def update(

endpoint = f"{PROJECTS_ENDPOINT}/{self.id}"
response_json = self.put(endpoint, params, api_key=api_key)
return Project(**response_json)
return self._update(**response_json)

def workable_by_surger(self, surger_id, api_key: str = None):
"""
Expand Down