Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@caviri
Copy link
Member

@caviri caviri commented Jun 24, 2024

When running the S3 setup, it gave an error due to a redundant method for creating folders. I changed the previous method, createFolderStructure, and provided some previous checking for bucket availability.

@caviri caviri requested a review from sabinem June 24, 2024 13:11
Copy link
Contributor

@sabinem sabinem left a comment

Choose a reason for hiding this comment

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

@caviri Normally function should just do their job or throw an error if they encounter something wrong. Then errors can bubble up to the surface (user interface) where hard crashes should be avoided. This is why in the cli and in the dashboard, try excepts blocks are used to avoid crashes. Then in the except, you usually set log.exception besides a response to the user. Since log.exception also provides the traceback.


odtpS3 = s3Manager()
odtpS3.create_folders(["odtp"])
bucketAvailable = odtpS3.test_connection()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in try except block and not the db function:

  • in case an error occurs it bubbles up and this is fine: it should be caught at the interface to the user, which is either the cli or the dashboard.

odtp/storage.py Outdated
def test_connection(self):
bucket = self.s3.head_bucket(Bucket=self.bucketName)
return bucket
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

This can stay as it is: no need for a try except block.

@caviri
Copy link
Member Author

caviri commented Jun 26, 2024

I understand, yes it makes completely sense. Thanks @sabinem. I added your suggestion. Do you mind to take another look? I'm using log.error and log.exception.

Copy link
Contributor

@sabinem sabinem left a comment

Choose a reason for hiding this comment

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

@caviri I added one commit: a4879f8 since you forgot to adjust this reference to the changed return value.

There is another tiny comment: you assign the bucket but then don't return that value. I don't think we need the assignment in this case.

Anyway it should work fin now, so I already approve the PR.

try:
s3 = s3Manager()
bucket = s3.test_connection()
s3.test_connection()
Copy link
Contributor

Choose a reason for hiding this comment

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

@caviri I added a commit to correct this call, since you are not returning the bucket any more. Now it should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I missed that. Thanks!

odtp/storage.py Outdated
self.bucketName = settings.ODTP_BUCKET_NAME

def test_connection(self):
bucket = self.s3.head_bucket(Bucket=self.bucketName)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: why assign the bucket if it is not returned?

Copy link
Member Author

Choose a reason for hiding this comment

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

Accepted

@caviri caviri merged commit 14bacff into develop Jun 26, 2024
@caviri caviri deleted the Setup-initiation branch June 26, 2024 18:55
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