Skip to content

Test on Django 5.2, Python 3.13#3467

Merged
hmpf merged 5 commits intoUninett:masterfrom
hmpf:test/django5.2
Sep 17, 2025
Merged

Test on Django 5.2, Python 3.13#3467
hmpf merged 5 commits intoUninett:masterfrom
hmpf:test/django5.2

Conversation

@hmpf
Copy link
Copy Markdown
Contributor

@hmpf hmpf commented Aug 27, 2025

Scope and purpose

Dependent on #3266.

Django 4.2 does not support python 3.13 so we need to upgrade Django for the sake of running on debian trixie.

Replaces #3269, but see that for a list of usage of naive datetimes.

Looks of dates and numbers might change, we might have to manually look through the frontend and override if necessary.

This pull request

  • adds/changes/removes a dependency

We need a newer feedparser and psycopg2. Psycopg2 is in maintenance mode, we should consider switching to psycopg 3.

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • This pull request is based on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • [ ] If this results in changes in the UI: Added screenshots of the before and after
  • [ ] If this adds a new Python source code file: Added the boilerplate header to that file

@hmpf hmpf added upgrade django psycopg dependencies Pull requests that update a dependency file labels Aug 27, 2025
@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Aug 27, 2025

Warnings, unit-py313-django52:

Regexp warnings:

REPO/tests/unittests/web/webfront_test.py::test_tools_should_be_split_in_3_columns PASSED [100%]<unknown>:400: SyntaxWarning: invalid escape sequence '\['
<unknown>:401: SyntaxWarning: invalid escape sequence '\('
<unknown>:403: SyntaxWarning: invalid escape sequence '\s'
REPO/python/nav/bin/radiusparser.py:400: SyntaxWarning: invalid escape sequence '\['
  '^(?P<time>.*) : (?P<type>Auth): (?P<message>(?P<status>.*?): \[(?P<user>.*?)\] '
REPO/python/nav/bin/radiusparser.py:401: SyntaxWarning: invalid escape sequence '\('
  '\(from client (?P<client>[^ ]+) port (?P<port>[^ ]+)( cli (?P<cli>[^ ]+)|)\))\s*$'
REPO/python/nav/bin/radiusparser.py:403: SyntaxWarning: invalid escape sequence '\s'
  other_pattern = re.compile('^(?P<time>.*) : (?P<type>[^:]+): (?P<message>.*?)\s*$')

Other warnings:

REPO/python/nav/django/settings.py:77
  REPO/python/nav/django/settings.py:77: UserWarning: Could not get connection parameters from db.conf: [Errno 2] No such file or directory: 'db.conf'
    warnings.warn(f"Could not get connection parameters from db.conf: {e}")

TOXVENV/lib/python3.13/site-packages/django/conf/__init__.py:267
  TOXVENV/lib/python3.13/site-packages/django/conf/__init__.py:267: RemovedInDjango50Warning: The USE_L10N setting is deprecated. Starting with Django 5.0, localized formatting of data will always be enabled. For example Django will display numbers and dates using the format of the current locale.
    warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning)

REPO/tests/unittests/dhcpstats/kea_dhcp_test.py:0
  REPO/tests/unittests/dhcpstats/kea_dhcp_test.py:0: PytestCollectionWarning: cannot collect test class 'TestData' because it has a __new__ constructor (from: REPO/tests/unittests/dhcpstats/kea_dhcp_test.py)

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.07%. Comparing base (437d239) to head (6af3c50).
⚠️ Report is 326 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3467      +/-   ##
==========================================
+ Coverage   62.05%   62.07%   +0.02%     
==========================================
  Files         611      611              
  Lines       44854    44854              
  Branches       43       43              
==========================================
+ Hits        27835    27845      +10     
+ Misses      17009    16999      -10     
  Partials       10       10              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Aug 27, 2025

Failed test, integration-py313-django52:

___________________ ERROR collecting tests/integration/widget_test.py ____________________
ImportError while importing test module 'REPO/tests/integration/widget_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.13/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/widget_test.py:6: in <module>
    from nav.web.navlets.feedreader import FeedReaderNavlet
python/nav/web/navlets/feedreader.py:18: in <module>
    import feedparser
TOXVENV/lib/python3.13/site-packages/feedparser/__init__.py:28: in <module>
    from .api import parse
TOXVENV/lib/python3.13/site-packages/feedparser/api.py:35: in <module>
    from .encodings import convert_to_utf8
TOXVENV/lib/python3.13/site-packages/feedparser/encodings.py:29: in <module>
    import cgi
E   ModuleNotFoundError: No module named 'cgi'

Fixed by upgrading feedparser.

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Aug 27, 2025

Warnings, integration-py313-django52:

tests/integration/report/generator_test.py: 1 warning
tests/integration/watchdog_test.py: 6 warnings
tests/integration/web/auth/utils_test.py: 5 warnings
tests/integration/web/netmap_test.py: 2 warnings
tests/integration/web/webfront_test.py: 1 warning
  TOXVENV/lib/python3.13/site-packages/django/core/cache/backends/filebased.py:169: DeprecationWarning: glob.glob1 is deprecated and will be removed in Python 3.15. Use glob.glob and pass a directory to its root_dir argument instead.
    for fname in glob.glob1(self._dir, "*%s" % self.cache_suffix)

tests/integration/web/jwt_test.py::test_posting_existing_token_id_to_delete_endpoint_should_delete_token
  TOXVENV/lib/python3.13/site-packages/django/views/generic/base.py:98: DeleteViewCustomDeleteWarning: DeleteView uses FormMixin to handle POST requests. As a consequence, any custom deletion logic in JWTDelete.delete() handler should be moved to form_valid().
    self = cls(**initkwargs)

tests/integration/widget_test.py: 191 warnings
  TOXVENV/lib/python3.13/site-packages/feedparser/html.py:152: DeprecationWarning: 'count' is passed as positional argument
    data = re.sub(r'<!((?!DOCTYPE|--|\[))', r'&lt;!\1', data, re.IGNORECASE)

tests/integration/widget_test.py::test_get_pdu_navlet_in_edit_mode_should_return_200
  TOXVENV/lib/python3.13/site-packages/django/template/base.py:1047: RemovedInDjango50Warning: The "default.html" templates for forms and formsets will be removed. These were proxies to the equivalent "table.html" templates, but the new "div.html" templates will be the default from Django 5.0. Transitional renderers are provided to allow you to opt-in to the new output style now. See https://docs.djangoproject.com/en/4.2/releases/4.1/ for more details
    value = str(value)

I don't think there's anything here fixable by us.

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Aug 27, 2025

functional-py313-django52 has no additional warnings or errors, green!

@hmpf hmpf self-assigned this Aug 27, 2025
@hmpf hmpf mentioned this pull request Aug 27, 2025
@hmpf hmpf requested a review from lunkwill42 August 27, 2025 08:17
@lunkwill42
Copy link
Copy Markdown
Member

lunkwill42 commented Aug 27, 2025

REPO/python/nav/django/settings.py:77
  REPO/python/nav/django/settings.py:77: UserWarning: Could not get connection parameters from db.conf: [Errno 2] No such file or directory: 'db.conf'
    warnings.warn(f"Could not get connection parameters from db.conf: {e}")

This is an explicit NAV warning. You will almost always see this in a dev or test environment where the database hasn't been configured (or in production if the db.conf file isn't found), regardless of Python version. Not all tests set up the database, which is why you see it.

@hmpf hmpf force-pushed the test/django5.2 branch 4 times, most recently from d2d2aaf to 9082e1b Compare September 9, 2025 09:50
@hmpf hmpf marked this pull request as ready for review September 9, 2025 10:59
@hmpf hmpf requested a review from a team September 9, 2025 11:12
Copy link
Copy Markdown
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

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

Just small things

@hmpf hmpf force-pushed the test/django5.2 branch 2 times, most recently from 5632622 to 2696aaa Compare September 15, 2025 09:49
@hmpf hmpf requested a review from johannaengland September 16, 2025 07:21
@sonarqubecloud
Copy link
Copy Markdown

@hmpf hmpf merged commit 7fd48ff into Uninett:master Sep 17, 2025
18 checks passed
@hmpf hmpf deleted the test/django5.2 branch September 17, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file django psycopg upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants