Skip to content

Conversation

@ajaniszewska-dev
Copy link

@ajaniszewska-dev ajaniszewska-dev commented May 30, 2022

specs:
1. remove global var
2. add flag s3_bucket_exists on the backend
3. btn action_ensure_bucket_exists to test if the bucket exists by calling _ensure_bucket_exists
4. modify _check_bucket_exists to accept a flag force=False
5. if the force flag is false and self.s3_bucket_exists is True return True
6. if test is ok, set the flag
7. if the bucket is not available, create it and set the flag
8. no more call to check if the bucket exists

)


def action_ensure_bucket_exists(self):
Copy link
Author

@ajaniszewska-dev ajaniszewska-dev May 30, 2022

Choose a reason for hiding this comment

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

to clarify:

  1. btn action_ensure_bucket_exists to test if the bucket exists by calling _ensure_bucket_exists

I am not sure how do we want to test bucket connection here, I assumed that we want to start flow for getting bucket and forcing flag to True so we make sure call to head_bucket is made.

Copy link
Member

@simahawk simahawk May 30, 2022

Choose a reason for hiding this comment

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

TBH I forgot I added a generic way for defining validation of backends. Please check action_test_config in storage_backend -> it works if you define a validate_config method on the adapter.
Which means that we can:

  1. rename s3_bucket_exists to validated and move it to storage_backend and let action_test_config set it to True or False when needed (do this in its own commit pls)
  2. define validate_config and make it call _check_bucket_exists
  3. get rid of the custom btn

Copy link
Author

Choose a reason for hiding this comment

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

@simahawk just checking both modules, in storage_backend there is already a field 'has_validation'. Are we sure we want another field with basically same functionality there?

@ajaniszewska-dev ajaniszewska-dev force-pushed the s3-improve-get-bucket_add_flag branch 3 times, most recently from 7bc809f to 7c06954 Compare May 31, 2022 13:29
@ajaniszewska-dev ajaniszewska-dev force-pushed the s3-improve-get-bucket_add_flag branch from 7c06954 to 3e0f851 Compare May 31, 2022 13:46
@ajaniszewska-dev ajaniszewska-dev force-pushed the s3-improve-get-bucket_add_flag branch from f8d2050 to 122d400 Compare May 31, 2022 14:04
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2022

Codecov Report

Merging #1 (122d400) into s3-improve-get-bucket (cc855ee) will decrease coverage by 0.16%.
The diff coverage is 54.54%.

@@                    Coverage Diff                    @@
##           s3-improve-get-bucket       #1      +/-   ##
=========================================================
- Coverage                  86.51%   86.34%   -0.17%     
=========================================================
  Files                         41       41              
  Lines                       1305     1311       +6     
=========================================================
+ Hits                        1129     1132       +3     
- Misses                       176      179       +3     
Impacted Files Coverage Δ
storage_backend_s3/components/s3_adapter.py 69.30% <44.44%> (-6.74%) ⬇️
storage_backend/models/storage_backend.py 80.20% <100.00%> (+0.20%) ⬆️
storage_media_product/models/product.py 87.09% <0.00%> (+16.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc855ee...122d400. Read the comment docs.

)
has_validation = fields.Boolean(compute="_compute_has_validation")

validated = fields.Boolean(string="Validated",compute="_compute_has_validation")
Copy link
Member

Choose a reason for hiding this comment

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

what is this? It should be a normal stored field, not computed :/

for rec in self:
adapter = self._get_adapter()
rec.has_validation = hasattr(adapter, "validate_config")
rec.validated = rec.has_validation = hasattr(adapter, "validate_config")
Copy link
Member

Choose a reason for hiding this comment

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

pls rollback this

s3 = boto3.resource("s3", **params)
bucket_name = self.collection.aws_bucket
bucket = self._get_or_create_bucket(s3, bucket_name, **params)
self.collection.validated = True
Copy link
Member

Choose a reason for hiding this comment

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

this writes on EVERY lookup for the bucket, pls drop it

s3.meta.client.head_bucket(Bucket=bucket_name)
# The call above is expensive, avoid it when possible.
EXISTING_BUCKETS.append(bucket_name)
self.collection.validated = True
Copy link
Member

Choose a reason for hiding this comment

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

you are writing on this a second time because is done already on line 148.
Drop this and rely only on the flag that this method should return and update the flag only in validate_config

simahawk pushed a commit that referenced this pull request Dec 12, 2023
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Jan 22, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Feb 20, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
sebalix pushed a commit that referenced this pull request Mar 4, 2025
leemannd pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Mar 21, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
simahawk pushed a commit that referenced this pull request Apr 1, 2025
Ricardoalso pushed a commit that referenced this pull request Sep 24, 2025
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