-
Notifications
You must be signed in to change notification settings - Fork 5
fix(S3 Initiation): Fix for S3 initial setup #156
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
Conversation
sabinem
left a comment
There was a problem hiding this 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.
odtp/cli/setup.py
Outdated
|
|
||
| odtpS3 = s3Manager() | ||
| odtpS3.create_folders(["odtp"]) | ||
| bucketAvailable = odtpS3.test_connection() |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
|
I understand, yes it makes completely sense. Thanks @sabinem. I added your suggestion. Do you mind to take another look? I'm using |
sabinem
left a comment
There was a problem hiding this 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepted
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.