Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading spreadsheet for updates #15

Closed
wants to merge 27 commits into from
Closed

Conversation

aaclan-ebi
Copy link
Contributor

@aaclan-ebi aaclan-ebi commented Jul 6, 2021

@aaclan-ebi aaclan-ebi changed the title Uploading spreadsheet for updates, failing tests Uploading spreadsheet for updates Jul 6, 2021
@aaclan-ebi aaclan-ebi force-pushed the feature/spreadsheet-updates branch from 478968a to 0f510d8 Compare July 6, 2021 11:23
@aaclan-ebi aaclan-ebi force-pushed the feature/spreadsheet-updates branch from 75cf343 to 7dc73f9 Compare July 6, 2021 17:57
@aaclan-ebi aaclan-ebi changed the base branch from master to dev July 6, 2021 17:58
@aaclan-ebi aaclan-ebi self-assigned this Jul 7, 2021
@aaclan-ebi aaclan-ebi requested a review from a team July 7, 2021 11:06
@aaclan-ebi aaclan-ebi marked this pull request as ready for review July 7, 2021 11:06
@aaclan-ebi aaclan-ebi requested a review from a team July 7, 2021 13:04
@aaclan-ebi aaclan-ebi force-pushed the feature/spreadsheet-updates branch from 767d4e4 to 4e3148b Compare July 7, 2021 13:24
broker/service/spreadsheet_upload_service.py Show resolved Hide resolved
test/service/test_spreadsheet_generator.py Show resolved Hide resolved
def tearDown(self) -> None:
if self.test_file:
if os.path.exists(self.test_file):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could use the tempfile library for tempfiles that automatically delete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, very nice lib! thanks!

test/test_broker_app.py Outdated Show resolved Hide resolved
test/service/test_spreadsheet_upload_service.py Outdated Show resolved Hide resolved
@aaclan-ebi aaclan-ebi requested a review from a team July 7, 2021 20:34
ke4
ke4 previously approved these changes Jul 8, 2021
Copy link
Contributor

@ke4 ke4 left a comment

Choose a reason for hiding this comment

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

LGTM

raise SpreadsheetUploadError(401, "An authentication token must be supplied when uploading a spreadsheet")
self.ingest_api.set_token(token)

def upload(self, submission_url, path, project_uuid=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is upload for a full project rather than just updates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The upload function is for uploading spreadsheets with new entities. Sometime's the project is created before submission so we supply it if it already exists.

submission_resource = self.ingest_api.create_submission()
return submission_resource

def _assert_token_exists(self, token):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this input validation code? assert makes it sound like testing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to _validate_token_exists

broker_app.py Outdated
ingest_api = IngestApi()
spreadsheet_generator = SpreadsheetGenerator(ingest_api)
spreadsheet_job_manager = SpreadsheetJobManager(spreadsheet_generator, SPREADSHEET_STORAGE_DIR)
global ingest_api
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using global a safe approach?
Should we use flask's app context instead? or the "g" object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, i didn't know about that. Applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm it doesn't function as a global variable.

This is a good place to store resources during a request. During testing, you can use the Faking Resources and Context pattern to pre-configure such resources.

I'll revert to using the global :(

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be my lack of knowledge, but why are we defining these 3 variables here and once again at the setup method?

@@ -12,7 +13,13 @@
import tempfile
import yaml


# TODO these are integration tests, could either move to a separate directory
Copy link
Contributor

Choose a reason for hiding this comment

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

good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the comments, I already moved them now to a separate directory to make it easier to run tests locally 😅

amnonkhen
amnonkhen previously approved these changes Jul 8, 2021
@aaclan-ebi aaclan-ebi dismissed stale reviews from amnonkhen and ke4 via a953c09 July 8, 2021 12:33
Copy link
Contributor

@ke4 ke4 left a comment

Choose a reason for hiding this comment

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

I made a tiny comment. Could we clarify it, please?
Tx

broker_app.py Outdated
ingest_api = IngestApi()
spreadsheet_generator = SpreadsheetGenerator(ingest_api)
spreadsheet_job_manager = SpreadsheetJobManager(spreadsheet_generator, SPREADSHEET_STORAGE_DIR)
global ingest_api
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be my lack of knowledge, but why are we defining these 3 variables here and once again at the setup method?

@aaclan-ebi
Copy link
Contributor Author

aaclan-ebi commented Jul 9, 2021

@ke4 i think you're right, they're not needed. I removed them and moved the setup function on top to make it clearer there are global vars to be initialised. I don't know how else to avoid using global vars at the moment. But, I can see the performance benefit of it that it only initialises the schema template obj which is being used in template spreadsheet generation only once instead of initialising it every request so I'd like to retain the use of global vars for now.


try:
logger.info('Uploading spreadsheet!')
submission_resource = spreadsheet_upload_svc.async_upload(token, request_file, is_update, project_uuid)
submission_resource = spreadsheet_upload_svc.async_upload(token, request_file, is_update, project_uuid, submission_uuid)
Copy link
Contributor

Choose a reason for hiding this comment

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

The is_update param is just passed through here, and there is subsequent branching logic further down the execution sequence.
This smells of unclean design. Maybe there would be room here for the "strategy" pattern.

Copy link
Contributor Author

@aaclan-ebi aaclan-ebi Jul 9, 2021

Choose a reason for hiding this comment

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

I'm afraid I don't have time to implement that for this sprint.

@@ -8,7 +8,7 @@ itsdangerous==0.24
jdcal==1.4
MarkupSafe==1.1
werkzeug>=0.15.3
-e git+https://github.com/ebi-ait/ingest-client.git@7f04ab9a#egg=hca_ingest
-e git+https://github.com/ebi-ait/ingest-client.git@7038dcb#egg=hca_ingest
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not using a normal version number? (x.y.z)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done this way in the early development of the ingest-client python lib. It wasn't changed yet. We should also set up and release build for the ingest-client repo so that it'll release the module to PyPI every merges to master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I filed a ticket for the ingest-client CI/CD setup: ebi-ait/dcp-ingest-central#385

@aaclan-ebi
Copy link
Contributor Author

Hi @amnonkhen , I would like to merge this today so that I can deploy and hand over to a wrangler for testing, we could apply those comments later.

broker_app.py Show resolved Hide resolved
broker_app.py Show resolved Hide resolved
@aaclan-ebi
Copy link
Contributor Author

Closing in favour of PR #16 . This branch was already merged with that branch.

@aaclan-ebi aaclan-ebi closed this Jul 13, 2021
@MightyAx MightyAx deleted the feature/spreadsheet-updates branch October 5, 2022 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants