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

Fallback to the original behavior if prefix is not available (#1068) #1499

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ application specific configuration.
Loading the config from a Python module requires the ``python:``
prefix.

.. versionchanged:: 19.8
Pre-19.4 behavior of loading a config file without a ``python:``
prefix is now restored.

Server Socket
-------------

Expand Down
12 changes: 7 additions & 5 deletions gunicorn/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ def load_config_from_module_name_or_filename(self, location):
if location.startswith("python:"):
module_name = location[len("python:"):]
cfg = self.get_config_from_module_name(module_name)
else:
if location.startswith("file:"):
filename = location[len("file:"):]
else:
filename = location
elif location.startswith("file:"):
filename = location[len("file:"):]
cfg = self.get_config_from_filename(filename)
else:
try:
cfg = self.get_config_from_module_name(location)
Copy link
Owner

Choose a reason for hiding this comment

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

if we re-add that feature, wouldn’it be better to add the warning based kn the principle of least astonishment? Espacially since this chang re-add a behaviour removed 2 years ago. thoughts?

except ImportError:
cfg = self.get_config_from_filename(location)

for k, v in cfg.items():
# Ignore unknown names
Expand Down
4 changes: 4 additions & 0 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ class ConfigFile(Setting):
.. versionchanged:: 19.4
Loading the config from a Python module requires the ``python:``
prefix.

.. versionchanged:: 19.8
Pre-19.4 behavior of loading a config file without a ``python:``
prefix is now restored.
"""

class Bind(Setting):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ def test_load_config_module():
assert app.cfg.proc_name == "fooey"


@pytest.mark.parametrize("options", [
["-c", cfg_module()],
["-c", cfg_file()],
])
def test_load_config_fallback(options):
cmdline = ["prog_name"]
cmdline.extend(options)
with AltArgs(cmdline):
app = NoConfigApp()
assert app.cfg.bind == ["unix:/tmp/bar/baz"]
assert app.cfg.workers == 3
assert app.cfg.proc_name == "fooey"


def test_cli_overrides_config():
with AltArgs(["prog_name", "-c", cfg_file(), "-b", "blarney"]):
app = NoConfigApp()
Expand Down