Skip to content

Conversation

manggit
Copy link
Contributor

@manggit manggit commented Apr 29, 2025

Closes #79

Description

This PR addresses Issue #79 where passing a fully-qualified URL to request_rest.get() or request_rest.post() would incorrectly prepend the base URL, resulting in an invalid request.

Changes

  • Add a new class that inherits from BaseAnvilHttpRequest
  • Allow for the URL passed in to be a fully qualified URL but validate that the URL points to Anvil
  • Tests for get and post that verify both relative paths and absolute URLs are handled correctly. <- Thank you @paulchino

@manggit manggit changed the title Absolute url Create class to handle absolute urls Apr 29, 2025
@manggit manggit requested a review from a team April 29, 2025 05:09
@manggit manggit closed this Apr 29, 2025
@manggit manggit reopened this Apr 29, 2025
Copy link
Contributor

@fostimus fostimus left a comment

Choose a reason for hiding this comment

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

In the original issue, it was about improving request_rest, while this stands up a new method. Should this be baked into request_rest so consumers benefit just from upgrading, or is this potentially breaking and should have people migrate to this new method?

]

def get_url(self):
return "" # Not used since we expect full URLs
Copy link
Contributor

Choose a reason for hiding this comment

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

need to define this? the base of this func throws an error, prob can keep if we don't want people to use this

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 is intentionally defined as an empty string, otherwise request_rest tries to append whatever URL is passed in to whatever is returned in get_url

Copy link
Contributor

Choose a reason for hiding this comment

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

if that's the case then yeah def, but doesn't this function get inherited from here? I'm not a python guy so idk how inheritance works here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does get inherited from there but we are overriding it here by returning an empty string

if should_raise:
with pytest.raises(
ValueError,
match="URL must start with one of: https://app.useanvil.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally this uses VALID_HOSTS somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

if should_raise:
with pytest.raises(
ValueError,
match="URL must start with one of: https://app.useanvil.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally this uses VALID_HOSTS somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -117,6 +117,10 @@ def request_rest(self, options: Optional[dict] = None):
api = RestRequest(self.client, options=options)
return api

def request_fully_qualified(self, options: Optional[dict] = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

idt this is actually used anywhere - looks like the func above is used here. a couple other placess too, probably should use this new version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, request_rest also doesnt seem to be called anywhere. I guess someone could use these if they wanted to when making other requests to Anvil

@manggit manggit merged commit 584762b into master Apr 29, 2025
5 checks passed
@manggit manggit deleted the absolute-url branch April 29, 2025 23:32
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.

request_rest improvement
3 participants