Skip to content

Comments

feat: expose requestId in geolocation(), add __contains__ to AsyncCache, add unit tests#52

Open
rohansachinpatil wants to merge 1 commit intovercel:mainfrom
rohansachinpatil:fix/geolocation-requestid-and-async-cache-contains
Open

feat: expose requestId in geolocation(), add __contains__ to AsyncCache, add unit tests#52
rohansachinpatil wants to merge 1 commit intovercel:mainfrom
rohansachinpatil:fix/geolocation-requestid-and-async-cache-contains

Conversation

@rohansachinpatil
Copy link

Changes

Bug: geolocation() missing requestId

The REQUEST_ID_HEADER_NAME ("x-vercel-id") constant was defined but
the raw request ID was never returned in the Geo dict. Added
requestId: str | None to the Geo TypedDict and populated it —
matching TypeScript SDK behaviour.

Fix: AsyncCache protocol inconsistency

The sync Cache protocol declared __contains__ but AsyncCache did
not. AsyncInMemoryCache was also missing the implementation. Fixed both.

Tests

Added two new test modules covering previously untested code:

  • tests/test_headers.py — 23 tests
  • tests/test_cache_inmemory.py — 39 tests

All 105 tests pass; ruff and mypy are clean on our changes.

- 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).
@vercel
Copy link

vercel bot commented Feb 22, 2026

@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.

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.

1 participant