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

Upgrade Django to 4.2.11 #3183

Merged
merged 16 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 app.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"description": "Base URL of the site. Has to be https://{app-name}.herokuapp.com.",
"required": true
},
"ALLOWED_HOSTS": {
"description": "A list of strings representing the host/domain names the site can serve. Has to be {app-name}.herokuapp.com.",
"required": true
},
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": {
"value": "python",
"description": "Needed for Google AutoML Translation.",
Expand Down
4 changes: 4 additions & 0 deletions docs/admin/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ you create:
Controls the base URL for the site, including the protocol and port.
Defaults to ``http://localhost:8000``, should always be set in production.

``ALLOWED_HOSTS``
A list of strings representing the host/domain names the site can serve.
Defaults to ``.localhost, 127.0.0.1, [::1]``, should always be set in production.

``SSH_CONFIG``
Contents of the ``~/.ssh/config`` file used when Pontoon connects to VCS
servers via SSH. Used for disabling strict key checking and setting the
Expand Down
2 changes: 1 addition & 1 deletion pontoon/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ It offers a query editor with:
- real-time error reporting,
- results folding,
- autogenerated docs on shapes and their fields,
- [introspection](http://docs.graphene-python.org/projects/django/en/latest/debug/) via the `__debug`.
- [introspection](http://docs.graphene-python.org/projects/django/en/latest/debug/) via the `_debug`.
2 changes: 1 addition & 1 deletion pontoon/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def resolve_localizations(obj, info, include_disabled, include_system):


class Query(graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name="__debug")
debug = graphene.Field(DjangoDebug, name="_debug")

# include_disabled=True will return both active and disabled projects.
# include_system=True will return both system and non-system projects.
Expand Down
2 changes: 1 addition & 1 deletion pontoon/api/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockResolveInfo:
"""

def __init__(self, query, fragments=None):
self.field_asts = query.selection_set.selections
self.field_nodes = query.selection_set.selections
self.fragments = fragments


Expand Down
6 changes: 3 additions & 3 deletions pontoon/api/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from graphql.language.ast import FragmentSpread
from graphql.language.ast import FragmentSpreadNode


def get_fields(info):
Expand Down Expand Up @@ -35,7 +35,7 @@ def get_fields(info):
def iterate_field_names(prefix, field):
name = field.name.value

if isinstance(field, FragmentSpread):
if isinstance(field, FragmentSpreadNode):
results = []
new_prefix = prefix
sub_selection = info.fragments[name].selection_set.selections
Expand All @@ -53,7 +53,7 @@ def iterate_field_names(prefix, field):
return results

results = []
for field_ast in info.field_asts:
for field_ast in info.field_nodes:
results.extend(iterate_field_names("", field_ast))

return results
4 changes: 4 additions & 0 deletions pontoon/base/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@


class RaygunExceptionMiddleware(Provider, MiddlewareMixin):
def __init__(self, get_response):
super().__init__(get_response)
self._async_check()

def process_exception(self, request, exception):
# Ignore non-failure exceptions. We don't need to be notified
# of these.
Expand Down
8 changes: 6 additions & 2 deletions pontoon/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3527,8 +3527,12 @@ def serialize(self):
"rejected": self.rejected,
"pretranslated": self.pretranslated,
"fuzzy": self.fuzzy,
"errors": [error.message for error in self.errors.all()],
"warnings": [warning.message for warning in self.warnings.all()],
"errors": []
if not self.pk
else [error.message for error in self.errors.all()],
"warnings": []
if not self.pk
else [warning.message for warning in self.warnings.all()],
}

def mark_changed(self):
Expand Down
6 changes: 3 additions & 3 deletions pontoon/base/tests/views/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pontoon.base.tests import po_file


@pytest.yield_fixture
@pytest.fixture
def translator_a(
member,
project_locale_a,
Expand All @@ -17,15 +17,15 @@ def translator_a(
yield member


@pytest.yield_fixture
@pytest.fixture
def readonly_project_locale(project_locale_a):
project_locale_a.readonly = True
project_locale_a.save()

yield project_locale_a


@pytest.yield_fixture
@pytest.fixture
def po_translation(translation_a):
"""
Some tests require entity with non-empty key.
Expand Down
3 changes: 1 addition & 2 deletions pontoon/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import re

import pytz
eemeli marked this conversation as resolved.
Show resolved Hide resolved
import requests
import tempfile
import time
Expand Down Expand Up @@ -451,7 +450,7 @@ def parse_time_interval(interval):

def parse_timestamp(timestamp):
return timezone.make_aware(
datetime.strptime(timestamp, "%Y%m%d%H%M"), timezone=pytz.UTC
datetime.strptime(timestamp, "%Y%m%d%H%M"), timezone=timezone.utc
)

start, end = interval.split("-")
Expand Down
8 changes: 4 additions & 4 deletions pontoon/batch/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pontoon.test.factories import TranslationFactory, ProjectLocaleFactory


@pytest.yield_fixture
@pytest.fixture
def batch_action(client, admin_client):
"""
Shortcut function to make API-call more readable in tests.
Expand All @@ -32,7 +32,7 @@ def _action(admin=False, **opts):
return _action


@pytest.yield_fixture
@pytest.fixture
def translation_dtd_unapproved():
translation = TranslationFactory.create(
string="Test Translation",
Expand All @@ -52,7 +52,7 @@ def translation_dtd_unapproved():
yield translation


@pytest.yield_fixture
@pytest.fixture
def translation_dtd_invalid_unapproved():
# Provide invalid characters in translation to cause checks to fail
translation = TranslationFactory.create(
Expand All @@ -73,7 +73,7 @@ def translation_dtd_invalid_unapproved():
yield translation


@pytest.yield_fixture
@pytest.fixture
def test_batch_edit_translations_no_user(client):
"""If there are no logged-in users, the view redirects to the login page."""
response = client.post(reverse("pontoon.batch.edit.translations"))
Expand Down
6 changes: 3 additions & 3 deletions pontoon/checks/tests/test_compare_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def mock_quality_check_args(
}


@pytest.yield_fixture
@pytest.fixture
def entity_with_comment(entity_a):
"""
A simple entity that contains pre-defined key and comment.
Expand All @@ -67,7 +67,7 @@ def entity_with_comment(entity_a):
return entity_a


@pytest.yield_fixture
@pytest.fixture
def plural_entity(entity_with_comment):
"""
Entity with plural string.
Expand All @@ -78,7 +78,7 @@ def plural_entity(entity_with_comment):
return entity_with_comment


@pytest.yield_fixture
@pytest.fixture
def plural_translation(translation_a):
translation_a.plural_form = 1
translation_a.string = "Plural translation for entity_a"
Expand Down
12 changes: 6 additions & 6 deletions pontoon/checks/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from pontoon.checks.libraries import run_checks


@pytest.yield_fixture
@pytest.fixture
def run_tt_checks_mock():
with patch("pontoon.checks.libraries.translate_toolkit.run_checks") as mock:
yield mock


@pytest.yield_fixture()
@pytest.fixture()
def entity_properties_mock():
"""
Mock of entity from a .properties file.
Expand All @@ -28,7 +28,7 @@ def entity_properties_mock():
yield mock


@pytest.yield_fixture()
@pytest.fixture()
def entity_dtd_mock():
"""
Mock of entity from a .dtd file.
Expand All @@ -44,7 +44,7 @@ def entity_dtd_mock():
yield mock


@pytest.yield_fixture()
@pytest.fixture()
def entity_properties_plurals_mock():
"""
Mock of entity from a .properties file.
Expand All @@ -59,7 +59,7 @@ def entity_properties_plurals_mock():
yield mock


@pytest.yield_fixture()
@pytest.fixture()
def entity_invalid_resource_mock():
"""
Mock of entity from a resource with unsupported filetype.
Expand All @@ -74,7 +74,7 @@ def entity_invalid_resource_mock():
yield mock


@pytest.yield_fixture()
@pytest.fixture()
def entity_ftl_mock():
"""
Mock of entity from a a .ftl file.
Expand Down
8 changes: 4 additions & 4 deletions pontoon/checks/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)


@pytest.yield_fixture()
@pytest.fixture()
def translation_properties(translation_a):
resource = translation_a.entity.resource
resource.path = "test.properties"
Expand All @@ -23,7 +23,7 @@ def translation_properties(translation_a):
yield translation_a


@pytest.yield_fixture
@pytest.fixture
def translation_compare_locales_warning(translation_properties):
# Create new instance
translation = Translation.objects.get(pk=translation_properties.pk)
Expand All @@ -35,7 +35,7 @@ def translation_compare_locales_warning(translation_properties):
yield translation


@pytest.yield_fixture
@pytest.fixture
def translation_compare_locales_error(translation_properties):
# Create new instance
translation = Translation.objects.get(pk=translation_properties.pk)
Expand All @@ -51,7 +51,7 @@ def translation_compare_locales_error(translation_properties):
yield translation


@pytest.yield_fixture
@pytest.fixture
def translation_pontoon_error(translation_a):
# Create new instance
translation = Translation.objects.get(pk=translation_a.pk)
Expand Down
2 changes: 1 addition & 1 deletion pontoon/checks/tests/test_translate_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pontoon.checks.libraries.translate_toolkit import run_checks


@pytest.yield_fixture()
@pytest.fixture()
def mock_locale():
"""Small mock of Locale object to make faster unit-tests."""
yield "en-US"
Expand Down
25 changes: 2 additions & 23 deletions pontoon/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ def _default_from_email():
"extensions": [
"jinja2.ext.do",
"jinja2.ext.loopcontrols",
"jinja2.ext.with_",
"jinja2.ext.i18n",
"jinja2.ext.autoescape",
"django_jinja.builtins.extensions.CsrfExtension",
"django_jinja.builtins.extensions.CacheExtension",
"django_jinja.builtins.extensions.TimezoneExtension",
Expand Down Expand Up @@ -707,27 +705,8 @@ def _default_from_email():
os.path.join(TAGADMIN_DIR, "dist"),
]


# Set ALLOWED_HOSTS based on SITE_URL setting.
def _allowed_hosts():
host = _get_site_url_netloc() # Remove protocol and path
result = [host]
# In order to be able to use ALLOWED_HOSTS to validate URLs, we need to
# have a version of the host that contains the port. This only applies
# to local development (usually the host is localhost:8000).
if ":" in host:
host_no_port = host.rsplit(":", 1)[0]
result = [host, host_no_port]

# add values from environment variable. Needed in case of URL/domain redirections
env_vars_str = os.getenv("ALLOWED_HOSTS", "127.0.0.1:8000")
env_vars = [x.strip() for x in env_vars_str.split(",")]
result.extend(env_vars)

return result


ALLOWED_HOSTS = lazy(_allowed_hosts, list)()
allowed_hosts = os.environ.get("ALLOWED_HOSTS")
ALLOWED_HOSTS = allowed_hosts.split(",") if allowed_hosts else []

# Auth
# The first hasher in this list will be used for new passwords.
Expand Down
6 changes: 3 additions & 3 deletions pontoon/translations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pontoon.test.factories import TranslationFactory


@pytest.yield_fixture
@pytest.fixture
def request_create_translation():
"""
Return a function to call the create_translation view with default parameters.
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_create_translation_force_suggestions(
assert Translation.objects.last().approved is False


@pytest.yield_fixture
@pytest.fixture
def properties_resource(resource_a):
"""
A resource to trigger Translate Toolkit and compare-locales checks at once.
Expand All @@ -127,7 +127,7 @@ def properties_resource(resource_a):
yield resource_a


@pytest.yield_fixture
@pytest.fixture
def properties_entity(entity_a, properties_resource):
"""
An entity from properties_resource.
Expand Down
Loading
Loading