feat: expose requestId in geolocation(), add __contains__ to AsyncCache, add unit tests#52
Open
rohansachinpatil wants to merge 1 commit intovercel:mainfrom
Conversation
- headers.py: add
equestId field to the Geo TypedDict and expose it
in the geolocation() return value. The REQUEST_ID_HEADER_NAME
constant ('x-vercel-id') was already defined but never read back out
into the Geo dict -- this brings parity with the TypeScript SDK.
- cache/types.py: add __contains__(key: str) -> bool to the
AsyncCache protocol so that it mirrors the sync Cache protocol
which already declares it. Without this, type-checkers could reject
key in async_cache_obj.
- cache/cache_in_memory.py: implement __contains__ on
AsyncInMemoryCache by delegating to its underlying sync
InMemoryCache. This makes key in cache work consistently for both
the sync and async variants.
- tests/test_headers.py (new): comprehensive unit tests for
ip_address, geolocation (including the new
equestId field),
_get_flag, and _region_from_request_id using lightweight request
stubs (no framework dependency).
- tests/test_cache_inmemory.py (new): unit tests for InMemoryCache
and AsyncInMemoryCache covering set/get/delete, TTL expiry, tag
invalidation, __contains__, __getitem__, and key transformer
utilities (default_key_hash_function, create_key_transformer).
|
@rohansachinpatil is attempting to deploy a commit to the Framework Test Matrix Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Bug:
geolocation()missingrequestIdThe
REQUEST_ID_HEADER_NAME("x-vercel-id") constant was defined butthe raw request ID was never returned in the
Geodict. AddedrequestId: str | Noneto theGeoTypedDict and populated it —matching TypeScript SDK behaviour.
Fix:
AsyncCacheprotocol inconsistencyThe sync
Cacheprotocol declared__contains__butAsyncCachedidnot.
AsyncInMemoryCachewas also missing the implementation. Fixed both.Tests
Added two new test modules covering previously untested code:
tests/test_headers.py— 23 teststests/test_cache_inmemory.py— 39 testsAll 105 tests pass; ruff and mypy are clean on our changes.