Skip to content

Commit

Permalink
fixes duplicate model creation for resubmission (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschrimpf authored May 20, 2023
1 parent dbf5f49 commit f773ef7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 7 additions & 5 deletions brainscore_core/submission/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def public_benchmark_identifiers(domain: str) -> List[str]:
def modelentry_from_model(model_identifier: str, public: bool, competition: Union[None, str],
submission: Submission, domain: str,
bibtex: Union[None, str] = None) -> Model:
model_entry, created = Model.get_or_create(name=model_identifier, owner=submission.submitter,
defaults={'domain': domain,
'public': public,
'submission': submission,
'competition': competition})
model_entry, created = Model.get_or_create(name=model_identifier,
defaults={
'owner': submission.submitter,
'domain': domain,
'public': public,
'submission': submission,
'competition': competition})
if bibtex and created: # model entry was just created and we can add bibtex
reference = reference_from_bibtex(bibtex)
model_entry.reference = reference
Expand Down
14 changes: 12 additions & 2 deletions tests/test_submission/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_uid_from_email_does_not_exist(self):
assert uid == None


def _mock_submission_entry():
return submissionentry_from_meta(jenkins_id=123, user_id=1, model_type='base_model')
def _mock_submission_entry(jenkins_id=123, user_id=1, model_type='base_model'):
return submissionentry_from_meta(jenkins_id=jenkins_id, user_id=user_id, model_type=model_type)


class TestModel(SchemaTest):
Expand All @@ -81,6 +81,16 @@ def test_model_with_bibtex(self):
submission=submission_entry, public=True, competition=None, bibtex=SAMPLE_BIBTEX)
assert entry.reference.year == '2013'

def test_resubmission(self): # make model entry from user 1, then retrieve model entry from user 2 ("resubmit")
submission_entry = _mock_submission_entry()
params = dict(model_identifier='dummy', domain='test', public=True, competition=None, bibtex=SAMPLE_BIBTEX)
original_entry = modelentry_from_model(**params, submission=submission_entry)
# resubmit
resubmission = _mock_submission_entry(user_id=2)
resubmit_entry = modelentry_from_model(**params, submission=resubmission)
# even though resubmission had different submitter, model owner should still be original user
assert original_entry.owner == resubmit_entry.owner


class _MockBenchmark(BenchmarkBase):
def __init__(self):
Expand Down

0 comments on commit f773ef7

Please sign in to comment.