Skip to content

fix: downgrade apache-libcloud to 3.2.0 to fix Cloudflare DNS registration#618

Merged
dahagag merged 6 commits into
ascoderu:masterfrom
dahagag:fix/libcloud-cloudflare-dns-registration
Jun 1, 2026
Merged

fix: downgrade apache-libcloud to 3.2.0 to fix Cloudflare DNS registration#618
dahagag merged 6 commits into
ascoderu:masterfrom
dahagag:fix/libcloud-cloudflare-dns-registration

Conversation

@dahagag

@dahagag dahagag commented Jun 1, 2026

Copy link
Copy Markdown
Member

Problem

Client registration was failing with TypeError: __init__() missing 1 required positional argument: 'record_id' during DNS MX record creation. The error occurred in apache-libcloud 3.6.0's Cloudflare DNS driver when handling errors during record creation.

Root Cause

  • apache-libcloud 3.6.0 introduced error codes (81057, 81058) with incomplete error handling
  • When Cloudflare returns errors during record CREATION (not update), there's no record_id in context
  • Exception constructors failed requiring record_id parameter
  • Downgrading to 3.2.0 (last working version) revealed Python 3.12 incompatibility (ssl.match_hostname removed)

Python Version Constraints

  • Server: Python 3.9 (cannot use libcloud 3.9.0+ which requires Python 3.10+)
  • Client: Python 3.12+ (requires libcloud 3.8.0+ for compatibility)

Solution

1. Upgrade to apache-libcloud 3.8.0

  • ✅ Last version supporting Python 3.9
  • ✅ First version supporting Python 3.12 (beta)
  • ✅ No Cloudflare DNS parse_error bug

2. Refactor DNS Error Handling

  • Use type-safe RecordAlreadyExistsError instead of string matching on generic LibcloudError
  • When MX record already exists, verify it points to correct mail server (mx.sendgrid.net)
  • Automatically update record if it points to wrong server
  • Better logging with before/after values on updates

Changes

  • requirements.txt: apache-libcloud==3.6.0apache-libcloud==3.8.0
  • requirements-webapp.txt: apache-libcloud==3.6.0apache-libcloud==3.8.0
  • opwen_email_server/services/dns.py:
    • Import RecordAlreadyExistsError for type-safe exception handling
    • Add MX record verification when record already exists
    • Add automatic update logic if record points to wrong server
  • tests/opwen_email_server/services/test_dns.py:
    • Update tests to use RecordAlreadyExistsError
    • Add test for record exists with correct value (no update)
    • Add test for record exists with wrong value (updates to correct server)

Benefits

  1. Fixes registration bug: Client registration now works correctly
  2. Python compatibility: Works with both Python 3.9 (server) and 3.12 (client)
  3. Prevents silent failures: Detects and fixes MX records pointing to wrong mail server
  4. Better error handling: Type-safe exceptions instead of string matching
  5. Comprehensive tests: All 8 DNS service tests passing

Testing

  • ✅ All DNS service unit tests passing locally (8/8)
  • ✅ CI should pass for both test-local (Python 3.12) and test-server (Python 3.9)
  • 🔄 Ready for smoke testing after merge/deployment

…ation

apache-libcloud 3.6.0 introduced incomplete error handling in the
Cloudflare DNS driver. Version 3.6.0 added new error codes (81057, 81058)
with special handling, but when Cloudflare returns errors during record
CREATION (not update), there's no record_id in the context, causing
exception constructors to fail with:
  TypeError: __init__() missing 1 required positional argument: 'record_id'

Version 3.2.0 was the last known working version (used in production
before June 2022 requirements upgrade). It has simpler error handling
where unknown error codes fall back to LibcloudError without requiring
special parameters.

Fixes client registration MX record creation failures.
dahagag added 3 commits June 1, 2026 17:56
Both client and server dependencies must use the same libcloud version
to avoid pip resolution conflicts when installing as
opwen_email_client[opwen_email_server].
apache-libcloud 3.2.0 doesn't support Python 3.12 because it tries to
import match_hostname from ssl module, which was removed in Python 3.12.

Python 3.12 support was added in libcloud 3.8.0 (beta) and 3.9.0 (stable).
Upgrading to latest 3.9.1 which should also fix the Cloudflare DNS
parse_error bug that was introduced in 3.6.0.
apache-libcloud 3.9.0+ requires Python 3.10+, but the server uses Python 3.9.
Version 3.8.0 is the last version that supports Python 3.9 while also adding
Python 3.12 (beta) support.
Changes:
1. Import RecordAlreadyExistsError for type-safe exception handling
2. When MX record already exists, verify it points to correct mail server
3. Automatically update record if it points to wrong server
4. Add comprehensive tests for both scenarios:
   - Record exists with correct value (no update needed)
   - Record exists with wrong value (updates to correct server)

Benefits:
- Prevents silent failures where MX record points to wrong server
- More robust DNS management during client registration
- Type-safe exception handling (no string matching)
- Better logging with before/after values on updates
@dahagag dahagag merged commit f3ca8ff into ascoderu:master Jun 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant