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

Fix deletion of records #43

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Fix deletion of records #43

merged 3 commits into from
Nov 14, 2024

Conversation

gerardkok
Copy link
Contributor

Deletion of records results in a stack trace in version 0.0.2.

Example

Create a record in TransIP's controlpanel, and try to remove it with octodns:

TRANSIP_ACCOUNT='<redacted>' TRANSIP_KEY=".transip.key" octodns-sync --config=config.yaml --doit
...
2024-11-14T10:59:48  [8331819072] INFO  Plan 
********************************************************************************
* <domain>.
********************************************************************************
* transip (TransipProvider)
*   Delete <ARecord A 86400, removeme.<domain>., ['10.10.10.10']>
*   Summary: Creates=0, Updates=0, Deletes=1, Existing Records=5
********************************************************************************


2024-11-14T10:59:48  [8331819072] INFO  TransipProvider[transip] apply: making 1 changes to <domain>.com.
Traceback (most recent call last):
  File "/Users/gerard/github/octodns/env/bin/octodns-sync", line 8, in <module>
    sys.exit(main())
  File "/Users/gerard/github/octodns/env/lib/python3.9/site-packages/octodns/cmds/sync.py", line 62, in main
    manager.sync(
  File "/Users/gerard/github/octodns/env/lib/python3.9/site-packages/octodns/manager.py", line 856, in sync
    total_changes += target.apply(plan)
  File "/Users/gerard/github/octodns/env/lib/python3.9/site-packages/octodns/provider/base.py", line 298, in apply
    self._apply(plan)
  File "/Users/gerard/github/octodns/env/lib/python3.9/site-packages/octodns_transip/__init__.py", line 259, in _apply
    if record.name == '' and record._type == 'NS':
AttributeError: 'NoneType' object has no attribute 'name'

I think the AttributeError is caused by record being None when removing records, because there is no new record with modified values in that case.

Fix

The fix seems to be to check if record is not None before checking its name and type in _apply. After adding that deletion works fine:

TRANSIP_ACCOUNT='<redacted>' TRANSIP_KEY=".transip.key" octodns-sync --config=config.yaml --doit
...
2024-11-14T11:10:14  [8331819072] INFO  Plan 
********************************************************************************
* <domain>.
********************************************************************************
* transip (TransipProvider)
*   Delete <ARecord A 86400, removeme.<domain>., ['10.10.10.10']>
*   Summary: Creates=0, Updates=0, Deletes=1, Existing Records=5
********************************************************************************


2024-11-14T11:10:14  [8331819072] INFO  TransipProvider[transip] apply: making 1 changes to <domain>.
2024-11-14T11:10:16  [8331819072] INFO  Manager sync:   1 total changes

safe navigation into attributes of record
octodns_transip/__init__.py Outdated Show resolved Hide resolved
octodns_transip/__init__.py Outdated Show resolved Hide resolved
gerardkok and others added 2 commits November 14, 2024 19:13
Co-authored-by: Ross McFarland <rwmcfa1@gmail.com>
Co-authored-by: Ross McFarland <rwmcfa1@gmail.com>
@gerardkok
Copy link
Contributor Author

I followed your suggestions, and agree that it's the cleaner solution. I also verified it fixes the issue; I could properly delete a record.

@ross ross merged commit e8f3b98 into octodns:main Nov 14, 2024
7 checks passed
@maikelpoot
Copy link
Contributor

@gerardkok Thnx, and apologies.

i guess this also means the testing doesn't properly test deletions.
Will try adding a test case today but added an issue just in case #44 to remind me.

@gerardkok
Copy link
Contributor Author

@maikelpoot Thanks, that's fine, no rush. I have looked into adding a unit test myself, but I'm not very familiar with Python test frameworks, so I didn't immediately see how it could be done.

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.

3 participants