Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(provider): ensure extra params take priority over old_record in _update_record#566

Merged
NewFuture merged 5 commits intomasterfrom
copilot/update-record-extra-parameter
Oct 15, 2025
Merged

fix(provider): ensure extra params take priority over old_record in _update_record#566
NewFuture merged 5 commits intomasterfrom
copilot/update-record-extra-parameter

Conversation

Copy link
Contributor

Copilot AI commented Oct 15, 2025

Issue

When calling _update_record() across providers, the extra parameter should take priority over values from old_record. However, CloudFlare provider had the priority order reversed for certain fields.

Problem

In ddns/provider/cloudflare.py, the _update_record method was incorrectly prioritizing old_record values over extra parameters:

# WRONG - old_record takes priority
extra["proxied"] = old_record.get("proxied", extra.get("proxied"))
extra["tags"] = old_record.get("tags", extra.get("tags"))
extra["settings"] = old_record.get("settings", extra.get("settings"))

This meant that even if a user explicitly passed proxied=True in the extra parameter, if the old record had proxied=False, the old value would be used instead of the user's intended value.

Solution

Corrected the priority order to ensure extra parameters always take precedence:

# CORRECT - extra takes priority
extra["proxied"] = extra.get("proxied", old_record.get("proxied"))
extra["tags"] = extra.get("tags", old_record.get("tags"))
extra["settings"] = extra.get("settings", old_record.get("settings"))

Now if the user provides a value in extra, it will be used. Only when extra doesn't contain the key will the old_record value be used as a fallback.

Testing

Added comprehensive unit tests for all BaseProvider implementations to verify correct priority behavior:

  • CloudflareProvider: Updated existing test to verify extra priority
  • HuaweiDNSProvider: New test test_update_record_extra_priority_over_old_record
  • AlidnsProvider: New test test_update_record_extra_priority_over_old_record
  • DnspodProvider: New test test_update_record_extra_priority_over_old_record
  • DnscomProvider: New test test_update_record_extra_priority_over_old_record
  • AliesaProvider: New test test_update_record_extra_priority_over_old_record
  • NamesiloProvider: New test test_update_record_extra_priority_over_old_record
  • TencentCloudProvider: New test test_update_record_extra_priority_over_old_record

All other providers were verified to already have correct priority implementation.

Test Results

  • ✅ All 218 provider tests passing
  • ✅ 8 new/updated tests for extra parameter priority
  • ✅ No regressions detected
  • ✅ Python 2.7 compatible
  • ✅ No unsafe eval() usage
  • ✅ Passes linting checks

Impact

Only CloudFlare provider behavior changes. When users specify proxied, tags, or settings through the extra parameter, these values will now correctly override the corresponding values from old_record, ensuring user intent is respected.

Fixes #565

Original prompt

This section details on the original issue you should resolve

<issue_title>_update_record 时 extra 优先级高于old record</issue_title>
<issue_description>对于所有provider _update_record 时候优先使用 extra 参数

并添加单元测试验证</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #565


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…update_record

- Fixed cloudflare.py: Changed priority order for proxied, tags, and settings
- Added comprehensive tests for all providers to verify extra parameter priority
- Tests added/updated: cloudflare, huaweidns, alidns, dnspod, dnscom, aliesa, namesilo, tencentcloud
- All 218 provider tests passing

Co-authored-by: NewFuture <[email protected]>
Copilot AI changed the title [WIP] Update _update_record to prioritize extra parameter fix(provider): ensure extra params take priority over old_record in _update_record Oct 15, 2025
Copilot AI requested a review from NewFuture October 15, 2025 14:29
@NewFuture
Copy link
Owner

@copilot fix py2.7 ImportError: No module named mock

- Changed from `from unittest.mock import patch` to `from base_test import patch`
- This ensures compatibility with Python 2.7 where mock is a separate package
- All 218 provider tests still passing

Co-authored-by: NewFuture <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot fix py2.7 ImportError: No module named mock

Fixed in commit 2e4d4f2. Changed the import from unittest.mock to use the Python 2.7 compatible import pattern via base_test.patch.

@NewFuture NewFuture marked this pull request as ready for review October 15, 2025 14:42
@NewFuture NewFuture requested a review from Copilot October 15, 2025 14:42
Copy link
Contributor

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 fixes a priority issue in the CloudFlare provider where old_record values were incorrectly taking precedence over user-provided extra parameters in _update_record(). The fix ensures that extra parameters always override old_record values, respecting user intent. Additionally, comprehensive unit tests were added across all BaseProvider implementations to verify correct priority behavior and prevent future regressions.

Key Changes:

  • Reversed priority order in CloudFlare provider for proxied, tags, and settings fields to prioritize extra over old_record
  • Added 8 new/updated unit tests across all providers to validate extra parameter priority
  • All 218 tests passing with no behavioral changes to other providers

Reviewed Changes

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

Show a summary per file
File Description
ddns/provider/cloudflare.py Fixed priority order to ensure extra parameters take precedence over old_record values for proxied, tags, and settings fields
tests/test_provider_cloudflare.py Updated existing test to verify correct priority behavior with additional test cases for tags and settings
tests/test_provider_huaweidns.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_alidns.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_dnspod.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_dnscom.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_aliesa.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_namesilo.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior
tests/test_provider_tencentcloud.py Added new test test_update_record_extra_priority_over_old_record to verify priority behavior

@NewFuture
Copy link
Owner

@copilot Using eval() to parse JSON is unsafe and should be replaced with json.loads(). While this is test code, it sets a bad example and could pose security risks if similar patterns are copied to production code.

- Replaced eval(call_kwargs["body"]) with json.loads(call_kwargs["body"])
- Using eval() to parse JSON is a security risk and bad practice
- json.loads() is the safe and proper way to parse JSON strings
- All tests still passing

Co-authored-by: NewFuture <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot Using eval() to parse JSON is unsafe and should be replaced with json.loads(). While this is test code, it sets a bad example and could pose security risks if similar patterns are copied to ...

Fixed in commit 4c8a7e3. Replaced eval() with json.loads() for safe JSON parsing in the tencentcloud test.

Copy link
Contributor

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@NewFuture NewFuture requested a review from Copilot October 15, 2025 15:17
Copy link
Contributor

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@NewFuture
Copy link
Owner

@copilot fix lint

Error: tests/test_provider_tencentcloud.py:236:1: W293 Blank line contains whitespace

… test

- Fixed W293 linting error on line 236
- Removed trailing whitespace from blank line after import statement
- All tests still passing

Co-authored-by: NewFuture <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot fix lint

Error: tests/test_provider_tencentcloud.py:236:1: W293 Blank line contains whitespace

...

Fixed in commit 8f2b9a1. Removed trailing whitespace from the blank line.

@NewFuture NewFuture enabled auto-merge (squash) October 15, 2025 15:52
@NewFuture NewFuture merged commit d910a06 into master Oct 15, 2025
33 of 38 checks passed
@NewFuture NewFuture deleted the copilot/update-record-extra-parameter branch October 15, 2025 16:08
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.

_update_record 时 extra 优先级高于old record

2 participants