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

Fix deprecation warning for get_storage_class #669

Merged
merged 2 commits into from
Dec 30, 2023

Conversation

albertyw
Copy link
Member

@albertyw albertyw commented Aug 6, 2023

This PR should fix the deprecation warning for get_storage_class by trying to import and use the storages class instead. However, the latter is not an exact replacement for the former, requiring a different configuration option to be provided under the STORAGE instead of the SILKY_STORAGE_CLASS setting. This makes this PR a forwards incompatible change requiring a minor semver bump.

Fixes #656

@codecov
Copy link

codecov bot commented Aug 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f24f055) 86.58% compared to head (b24978d) 86.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #669      +/-   ##
==========================================
+ Coverage   86.58%   86.65%   +0.06%     
==========================================
  Files          52       52              
  Lines        2102     2113      +11     
==========================================
+ Hits         1820     1831      +11     
  Misses        282      282              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +174 to +180
STORAGES = {
'SILKY_STORAGE': {
'BACKEND': 'path.to.StorageClass',
},
# ...
}
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

Copy link
Member

@50-Course 50-Course left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! It's great to see that the deprecation warning for get_storage_class being addressed in earnest.

I noticed that the PR introduces a forwards incompatibility by requiring a different configuration option (STORAGE) to be used instead of SILKY_STORAGE_CLASS - a major change that will require users to update their configuration files.

I'm also curious about how the storages class compares to the old get_storage_class approach in terms of functionality and performance.

Overall, I think this is a good PR that addresses an important issue.

@albertyw
Copy link
Member Author

The STORAGES config is defined by the Django framework itself and its predecessor get_storage_class is removed starting Django 5.1 so there's not much of an alternative to replacing get_storage_class. All users, whether using django-silk or not will be eventually forced to abandon get_storage_class and therefore SILKY_STORAGE_CLASS and set up a STORAGES config. Nevertheless, this change is a no-op for users using the default silk.storage.ProfilerResultStorage due to the try/except falling back to that storage if storages['SILKY_STORAGE'] is not specified.

In terms of performance, comparing the new storages object against the get_storage_class implementation, it seems that the former would be more performant due to it caching storages. Since django-silk is initializing silk_storage once on initialization rather than in the request-serving path, I don't think performance is a significant consideration though. Either storages configuration gives equivalent functionality; the change only affects configuration format.

@albertyw albertyw merged commit 23ff43b into jazzband:master Dec 30, 2023
19 checks passed
@albertyw albertyw deleted the django-storages branch December 30, 2023 21:05
@50-Course
Copy link
Member

The STORAGES config is defined by the Django framework itself and its predecessor get_storage_class is removed starting Django 5.1 so there's not much of an alternative to replacing get_storage_class. All users, whether using django-silk or not will be eventually forced to abandon get_storage_class and therefore SILKY_STORAGE_CLASS and set up a STORAGES config. Nevertheless, this change is a no-op for users using the default silk.storage.ProfilerResultStorage due to the try/except falling back to that storage if storages['SILKY_STORAGE'] is not specified.

In terms of performance, comparing the new storages object against the get_storage_class implementation, it seems that the former would be more performant due to it caching storages. Since django-silk is initializing silk_storage once on initialization rather than in the request-serving path, I don't think performance is a significant consideration though. Either storages configuration gives equivalent functionality; the change only affects configuration format.

Thanks for the explanation. Coming back to this in a few.

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.

RemovedInDjango51Warning for get_storage_class with Django 4.2
2 participants