Skip to content

[fix] Remove invalid escape sequence warnings in OpenWrt strings#403

Open
yassinekolsi wants to merge 1 commit into
openwisp:masterfrom
yassinekolsi:fix-openwrt-syntaxwarning-escapes
Open

[fix] Remove invalid escape sequence warnings in OpenWrt strings#403
yassinekolsi wants to merge 1 commit into
openwisp:masterfrom
yassinekolsi:fix-openwrt-syntaxwarning-escapes

Conversation

@yassinekolsi
Copy link
Copy Markdown

Summary
This PR removes Python 3.12+ invalid escape sequence SyntaxWarnings in OpenWrt upgrader/test strings.

Changes

  • Converted OpenWrt false-positive regex patterns to raw strings to avoid invalid escape warnings.
  • Updated false-positive regex patterns to match both escaped and unescaped path variants (e.g. /tmp and /tmp), preserving intended suppression behavior.
  • Simplified OpenWrt test fixture strings by removing unnecessary escaped forward slashes.

Behavior impact
No intended functional behavior change beyond keeping false-positive matching robust across escaped/unescaped log formats.

Validation

  • Before (warnings reproduced):
    • python3 -W default -m py_compile openwisp_firmware_upgrader/upgraders/openwrt.py openwisp_firmware_upgrader/tests/test_openwrt_upgrader.py
  • After (clean):
    • python3 -W error::SyntaxWarning -m py_compile openwisp_firmware_upgrader/upgraders/openwrt.py openwisp_firmware_upgrader/tests/test_openwrt_upgrader.py

Checklist

  • Read contributing guidelines.
  • Manually validated changes.
  • Updated test fixtures as needed.
  • Documentation update not needed for this housekeeping fix.

Copilot AI review requested due to automatic review settings March 24, 2026 16:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

Warning

Rate limit exceeded

@yassinekolsi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: db32b885-3303-4ac8-b1de-d877596e5429

📥 Commits

Reviewing files that changed from the base of the PR and between c142d19 and fee6be3.

📒 Files selected for processing (2)
  • openwisp_firmware_upgrader/tests/test_openwrt_upgrader.py
  • openwisp_firmware_upgrader/upgraders/openwrt.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes Python 3.12+ SyntaxWarning: invalid escape sequence warnings by updating OpenWrt upgrader false-positive regex patterns and related test fixture strings, while keeping the false-positive suppression behavior compatible with both escaped and unescaped log formats.

Changes:

  • Converted OpenWrt upgrader false-positive regex patterns to raw strings to eliminate invalid escape sequence warnings.
  • Adjusted the regex patterns to match both escaped (\/tmp) and unescaped (/tmp) path variants.
  • Simplified the OpenWrt upgrader test fixture error strings by removing unnecessary escaped forward slashes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
openwisp_firmware_upgrader/upgraders/openwrt.py Updates false-positive regex patterns (raw strings + optional escaped slash handling) used to suppress known sysupgrade “false failure” errors.
openwisp_firmware_upgrader/tests/test_openwrt_upgrader.py Updates the mocked sysupgrade failure message fixture to avoid invalid escape warnings by using unescaped paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 194 to 200
"Command failed: ubus call system sysupgrade "
'{ "prefix": "\/tmp\/root", '
f'"path": "\/tmp\/{filename}", '
'"backup": "\/tmp\/sysupgrade.tgz", '
'"command": "\/lib\/upgrade\/do_stage2", '
'{ "prefix": "/tmp/root", '
f'"path": "/tmp/{filename}", '
'"backup": "/tmp/sysupgrade.tgz", '
'"command": "/lib/upgrade/do_stage2", '
'"options": { "save_partitions": 1 } } '
"(Connection failed)"
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

The new false-positive suppression regex is intended to match both escaped (e.g. \/tmp) and unescaped (/tmp) path variants, but this test fixture now only exercises the unescaped form. Add a second test case (or parameterize this helper/test) that raises a CommandFailedException message containing literal backslashes before slashes so the escaped-log variant is covered and the new regex behavior is locked in.

Copilot uses AI. Check for mistakes.
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.

2 participants