Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Migrates custom storage backends (build-media, build-commands, build-tools) to Django's STORAGES setting, enabling use of the standard django.core.files.storage.storages API.

Changes

  • Settings: Added storage aliases to STORAGES property in base.py, docker_compose.py, and test.py
  • Storage module: Updated readthedocs/storage/__init__.py to use storages["alias"] instead of get_storage_class(settings.RTD_*)
  • Build tasks: Updated readthedocs/projects/tasks/storage.py to retrieve storage classes via storages API
  • Test files: Migrated proxito/tests/base.py and rtd_tests/tests/test_imported_file.py to new pattern
  • Deprecation: Added deprecation warning to get_storage_class() function

Usage

# Before
from readthedocs.storage import get_storage_class
storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)()

# After
from django.core.files.storage import storages
storage = storages["build-media"]

The lazy-loaded instances (build_media_storage, build_commands_storage, etc.) continue to work unchanged.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • search
    • Triggering command: /usr/bin/python python -m pytest readthedocs/rtd_tests/tests/test_imported_file.py -v --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Upgrade STORAGES setting to the new pattern</issue_title>
<issue_description>This is a follow up of the changes introduced in:

We upgrade our settings to be like:

    @property
    def STORAGES(self):
        return {
            "staticfiles": {
                "BACKEND": self.RTD_STATICFILES_STORAGE,
                "OPTIONS": {
                    "bucket_acl": "public-read",
                    "default_acl": "public-read",
                    "querystring_auth": False,
                },
            },

            "build-media": {
                "BACKEND": self.RTD_BUILD_MEDIA_STORAGE,
                "OPTIONS": {
                    "bucket_name": self.S3_MEDIA_STORAGE_BUCKET,
                    "custom_domain": self.S3_MEDIA_STORAGE_OVERRIDE_HOSTNAME,
                    "bucket_acl": "public-read",
                    "default_acl": "public-read",
                    "querystring_auth": False,
                },
            },

            # ... other storage backends here like `build-tools` and more ...
        }

With this, we will be able to delete all our classes and mixins to deal with multiple storages and make the code cleaner while using the Django standards:

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 1, 2025 11:48
Co-authored-by: humitos <244656+humitos@users.noreply.github.com>
Co-authored-by: humitos <244656+humitos@users.noreply.github.com>
Copilot AI changed the title [WIP] Upgrade STORAGES setting to the new pattern Upgrade STORAGES setting to use Django's standard pattern Dec 1, 2025
Copilot AI requested a review from humitos December 1, 2025 11:59
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me. I tested it locally and it worked. I will check -ops repositories and corporate now.

@humitos
Copy link
Member

humitos commented Dec 2, 2025

I will check -ops repositories and corporate now.

I didn't find any code that requires changes there.

@humitos humitos marked this pull request as ready for review December 2, 2025 10:07
@humitos humitos requested a review from a team as a code owner December 2, 2025 10:07
@humitos humitos requested a review from stsewd December 2, 2025 10:07
Comment on lines +63 to +64
storage = storages[alias]
return type(storage)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this can be done with

import_string(storages.backends[alias]['BACKEND'])

since there is no need for an instance

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we could use import_string but since the class is already imported, calling type over the instance makes more sense to me than re-importing.

serve.build_media_storage = get_storage_class(
settings.RTD_BUILD_MEDIA_STORAGE
)()
serve.build_media_storage = storages["build-media"]
Copy link
Member

Choose a reason for hiding this comment

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

Checking the comment, this instance is also probably cached and will make some tests fail.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that all tests are passing.

Copy link
Member

Choose a reason for hiding this comment

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

Should we remove this line completely? Seems Django is smart enough and it's not required anymore?

Suggested change
serve.build_media_storage = storages["build-media"]

class ConfiguredBuildMediaStorage(LazyObject):
def _setup(self):
self._wrapped = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)()
self._wrapped = storages["build-media"]
Copy link
Member

Choose a reason for hiding this comment

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

I think these were made in order to lazy instantiate the storage object. storages[alias] does that by default, probably? We should check, we don't need these wrappers otherwise.

Copy link
Member

@humitos humitos Dec 3, 2025

Choose a reason for hiding this comment

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

Hrm, I'm not sure. The documentation doesn't say too much about lazyness.

I asked AI about this and it says that storage[alias] is not lazy by default and we should do what we are currently doing if we want it to be lazy.

Copy link
Member

Choose a reason for hiding this comment

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

Co-authored-by: Santos Gallegos <stsewd@proton.me>
@read-the-docs-community
Copy link

read-the-docs-community bot commented Dec 3, 2025

Documentation build overview

📚 dev | 🛠️ Build #30549943 | 📁 Comparing 247f637 against latest (fd3bcfd)


🔍 Preview build

Show files changed (25 files in total): 📝 1 modified | ➕ 24 added | ➖ 0 deleted
File Status
http-routingtable.html ➕ added
index.html 📝 modified
design/apiv3.html ➕ added
design/better-doc-urls-handling.html ➕ added
design/build-images.html ➕ added
design/embed-api.html ➕ added
design/file-tree-diff.html ➕ added
design/flyout-redesign.html ➕ added
design/future-builder.html ➕ added
design/in-doc-search-ui.html ➕ added
design/index.html ➕ added
design/new-notifications-system.html ➕ added
design/new-search-api.html ➕ added
design/new-sphinx-guides.html ➕ added
design/organizations.html ➕ added
design/pr-builder.html ➕ added
design/privacy-levels.html ➕ added
design/redirects.html ➕ added
design/refactor-remote-repository.html ➕ added
design/secure-api-access-from-builders.html ➕ added
design/sphinx-jquery.html ➕ added
design/system-packages.html ➕ added
design/telemetry.html ➕ added
design/theme-context.html ➕ added
design/yaml-file.html ➕ added

@humitos humitos requested a review from stsewd December 3, 2025 12:24
@humitos
Copy link
Member

humitos commented Dec 9, 2025

@stsewd this is ready to re-review and merge from my side.

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.

Upgrade STORAGES setting to the new pattern

3 participants