Skip to content

Conversation

@kimallen
Copy link
Contributor

@kimallen kimallen commented Sep 16, 2025

Ticket

Resolves #4152

Changes

  • Replaces api library from requests to httpx in the CloudflareService methods
  • Fixes bug where updating nameservers was crashing

Context for reviewers

I'm not sure the best pattern for error handling/raising errors, and the error calls could be more granular. I'm open to suggestions, or this can be something we tackle in more depth later (both handling of errors and bubbling up of errors)

Setup

Should be able to use add a dns record to a domain that hasn't had one before and also new records to accounts/zones that already exist. See instructions for running locally
or test in sandbox kma (can use instructions from this PR to test with a new domain name)

Code Review Verification Steps

As the original developer, I have

Satisfied acceptance criteria and met development standards

  • Met the acceptance criteria, or will meet them in a subsequent PR
  • Created/modified automated tests
  • Update documentation in READMEs and/or onboarding guide

Ensured code standards are met (Original Developer)

  • If any updated dependencies on Pipfile, also update dependencies in requirements.txt.
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values

Validated user-facing changes (if applicable)

  • Follow the process for requesting a design review. If code is not user-facing, delete design reviewer checklist
  • Verify new pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

As a code reviewer, I have

Reviewed, tested, and left feedback about the changes

  • Pulled this branch locally and tested it
  • Verified code meets all checks above. Address any checks that are not satisfied
  • Reviewed this code and left comments. Indicate if comments must be addressed before code is merged
  • Checked that all code is adequately covered by tests
  • Verify migrations are valid and do not conflict with existing migrations

Validated user-facing changes as a developer

Note: Multiple code reviewers can share the checklists above, a second reviewer should not make a duplicate checklist. All checks should be checked before approving, even those labeled N/A.

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Meets all designs and user flows provided by design/product
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • (Rarely needed) Tested as both an analyst and applicant user

As a designer reviewer, I have

Verified that the changes match the design intention

  • Checked that the design translated visually
  • Checked behavior. Comment any found issues or broken flows.
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links

Validated user-facing changes as a designer

  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • Tested with multiple browsers (check off which ones were used)
    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

References

Screenshots

@kimallen kimallen force-pushed the kma/4152-use-httpx-for-dns-hosting branch from 4f2c3ef to 3b9bcd4 Compare September 16, 2025 17:52
@kimallen kimallen requested a review from a team September 16, 2025 17:56
@kimallen kimallen added the Feature: 🌐 DNS hosting Set some RRs in a .gov domain's zone label Sep 16, 2025
@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@asaki222 asaki222 self-assigned this Sep 17, 2025
self.dns_host_service.register_nameservers(zone_name, nameservers)
except (RegistryError, RegistrySystemError, Exception) as e:
logger.error(f"Error updating registry: {e}")

Copy link
Contributor

Choose a reason for hiding this comment

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

I might not have the full context here, but why was this error message updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, I was hitting an error that wasn't the original one (RegistrySystemError), so then it wasn't getting caught and the app was crashing. So I added other exceptions to catch it (at it's base it would at least be an Exception). I think error handling has a lot to be desired and I'm hoping to focus on a proper and comprehensive error handling pattern in a future ticket.

self.dns_record = None
self.client = Client()
self.dns_host_service = DnsHostService(client=self.client)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is awesome! It makes more flexible for other instances :-D

},
{"test_name": "RequestError", "error": {"exception": RequestError, "message": "Unknown error"}},
]

Copy link
Contributor

Choose a reason for hiding this comment

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

I like how you organized the the failure cases here

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

1 similar comment
@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@kimallen kimallen force-pushed the kma/4152-use-httpx-for-dns-hosting branch from 6f46df6 to 643e813 Compare September 23, 2025 22:45
@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

🥳 Successfully deployed to developer sandbox kma.

_ = UserDomainRole(user=self.user, domain=domain_contact, role="admin").save()
page = self.client.get(reverse("domain-security-email", kwargs={"domain_pk": domain_contact.id}))
_ = UserDomainRole(user=self.user, domain=domain, role="admin").save()
DomainInformation.objects.get_or_create(requester=self.user, domain=domain)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test wasn't actually testing what it was supposed to. The page wasn't actually rendering the domain because it was missing the data was not set up properly. Adding DomainInformation sets it up properly.

self.assertContains(response, "invited", count=5)
self.assertContains(response, "Invited", count=2)
self.assertContains(response, "retrieved", count=4)
self.assertContains(response, "invited", count=4)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These and the other adjusted counts in this PR are changed because one of the libraries that got updated changed the way the response html shows up. Previous, a lot more cruft (including queries) were showing up. With the updated, there's a lot less included in the response.

The tests in general need some work. They are not very clear what data is created or what data should be expected. For now they are basically serving as a "snapshot", so if something changes, we'll know. In the future, we should adjust the tests to be more effective and focused.

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

🥳 Successfully deployed to developer sandbox kma.

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

🥳 Successfully deployed to developer sandbox kma.

@kimallen kimallen merged commit 974d759 into main Oct 6, 2025
13 of 14 checks passed
@kimallen kimallen deleted the kma/4152-use-httpx-for-dns-hosting branch October 6, 2025 19:45
DaisyGuti pushed a commit that referenced this pull request Oct 27, 2025
* Add httpx library

* Update create_account and create_zone to use httpx library

* Fix nameserver call and exceptions

* Update create_dns_record to use httpx

* Update create_account tests

* Update create_zone tests

* Update create_dns_record tests

* Update fetches and tests

* Remove context manager and explicitly close client

* Update cloudflare_service tests to use new structure with client

* Update dns_host_service tests to pass in client

* Remove unused helper fn and fix black formatting

* Remove test domains from valid_domains list

* Remove import of non-exisistent module

* Refactor tests and include RequestError tests

* Fix linting issues

* Mock env't vars in test to pass CI

* Move vars into class vars; update test

* Fix linting issues

* Remove unused import

* Update tests to reflect new output of response html after library updates

* Update more tests

* Fix additional tests

* More fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: 🌐 DNS hosting Set some RRs in a .gov domain's zone

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Refactor http request for dns hosting to use httpx

3 participants