Skip to content

release: 0.22.0#623

Merged
stainless-app[bot] merged 15 commits intomainfrom
release-please--branches--main--changes--next
Apr 1, 2026
Merged

release: 0.22.0#623
stainless-app[bot] merged 15 commits intomainfrom
release-please--branches--main--changes--next

Conversation

@stainless-app
Copy link
Copy Markdown
Contributor

@stainless-app stainless-app bot commented Apr 1, 2026

Automated Release PR

0.22.0 (2026-04-01)

Full Changelog: v0.21.0...v0.22.0

Features

  • internal: implement indices array format for query and form serialization (e942e18)

Bug Fixes

  • deps: bump minimum typing-extensions version (d359d17)
  • pydantic: do not pass by_alias unless set (3679fc3)
  • sanitize endpoint path params (dc9d512)

Chores

  • ci: skip lint on metadata-only changes (e23a0d8)
  • internal: tweak CI branches (7e02151)
  • internal: update gitignore (e96f24b)
  • tests: bump steady to v0.19.4 (0ecf1e6)
  • tests: bump steady to v0.19.5 (757aae0)
  • tests: bump steady to v0.19.6 (95c72a9)
  • tests: bump steady to v0.19.7 (16d4263)
  • tests: bump steady to v0.20.1 (6f06faf)
  • tests: bump steady to v0.20.2 (5c4116d)

Refactors

  • tests: switch from prism to steady (0f01051)

This pull request is managed by Stainless's GitHub App.

The semver version number is based on included commit messages. Alternatively, you can manually set the version number in the title of this pull request.

For a better experience, it is recommended to use either rebase-merge or squash-merge when merging this pull request.

🔗 Stainless website
📚 Read the docs
🙋 Reach out for help or questions

@stainless-app
Copy link
Copy Markdown
Contributor Author

stainless-app bot commented Apr 1, 2026

🧪 Testing

To try out this version of the SDK:

pip install 'https://pkg.stainless.com/s/openlayer-python/6f06faf139d49d4ef42b1043f35ccb7c8653f067/openlayer-0.21.0-py3-none-any.whl'

Expires at: Fri, 01 May 2026 21:35:36 GMT
Updated at: Wed, 01 Apr 2026 21:35:36 GMT

@stainless-app stainless-app bot force-pushed the release-please--branches--main--changes--next branch from d85451e to c8199ba Compare April 1, 2026 21:35
Comment on lines +149 to 154
kwargs: _ModelDumpKwargs = {}
if by_alias is not None:
kwargs["by_alias"] = by_alias
return model.model_dump(
mode=mode,
exclude=exclude,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 The _ModelDumpKwargs dict built in model_dump is never spread into model.model_dump() — the explicit by_alias=bool(by_alias) if by_alias is not None else False on line 159 remains, so by_alias=False is unconditionally passed to pydantic when the caller omits the argument. This completely defeats the stated fix ('pydantic: do not pass by_alias unless set') and silently overrides model-level alias_generator defaults in pydantic v2/v3; the fix is to replace the explicit by_alias kwarg with **kwargs.

Extended reasoning...

What the bug is

In src/openlayer/_compat.py, the PR introduces a _ModelDumpKwargs TypedDict and, inside the pydantic-v2 branch of model_dump, conditionally populates it:

kwargs: _ModelDumpKwargs = {}
if by_alias is not None:
    kwargs["by_alias"] = by_alias

However, the subsequent model.model_dump() call still contains the old explicit argument:

return model.model_dump(
    mode=mode,
    exclude=exclude,
    exclude_unset=exclude_unset,
    exclude_defaults=exclude_defaults,
    warnings=True if PYDANTIC_V1 else warnings,
    by_alias=bool(by_alias) if by_alias is not None else False,  # never removed
)

The kwargs dict is built but never spread — **kwargs is absent. It is completely dead code.

The specific code path that triggers it

Every call to model_dump(model) (the default case, by_alias=None) hits the pydantic v2 branch, builds an empty kwargs, and then calls model.model_dump(..., by_alias=False) because bool(by_alias) if by_alias is not None else False evaluates to False.

Why existing code does not prevent it

The kwargs TypedDict construction looks correct in isolation, which makes the bug easy to miss. The explicit by_alias=... keyword was never removed from the model.model_dump() call site when **kwargs was supposed to replace it. There are no tests verifying that by_alias is absent from forwarded kwargs when not explicitly set, so the regression went undetected.

Impact

Pydantic v2 models that rely on model-level alias configuration (e.g., model_config = ConfigDict(alias_generator=..., populate_by_name=True)) will have their alias behavior silently overridden whenever model_dump is called without an explicit by_alias argument. Fields will be serialized using their Python attribute names instead of the configured aliases, potentially breaking serialization for any SDK model that uses aliased field names.

How to fix it

Remove the explicit by_alias=bool(by_alias) if by_alias is not None else False kwarg and replace with **kwargs:

return model.model_dump(
    mode=mode,
    exclude=exclude,
    exclude_unset=exclude_unset,
    exclude_defaults=exclude_defaults,
    warnings=True if PYDANTIC_V1 else warnings,
    **kwargs,
)

Step-by-step proof

  1. Caller invokes model_dump(my_model) with no by_alias argument — defaults to None.
  2. Code enters the if (not PYDANTIC_V1) or hasattr(model, "model_dump"): branch.
  3. kwargs: _ModelDumpKwargs = {} is created; the if by_alias is not None: guard is False, so kwargs remains {}.
  4. model.model_dump(..., by_alias=bool(None) if None is not None else False) simplifies to model.model_dump(..., by_alias=False).
  5. Pydantic v2 receives an explicit by_alias=False, overriding any model-level alias_generator default.
  6. The kwargs dict is never referenced again and is garbage-collected at end of scope.

Comment on lines +99 to +101
fragment_template: str | None = None
query_template: str | None = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Inside path_template(), the local variable path_template = rest (line ~107) shadows the enclosing function name for the rest of the function scope. While the current code works correctly because the name is never used after assignment to call the function, any future code added inside this function that tries to call path_template(...) would get a TypeError: str object is not callable instead of the expected function call. Rename the variable to path_str or path_portion to eliminate the shadowing.

Extended reasoning...

In src/openlayer/_utils/_path.py, the newly introduced function path_template contains this assignment near the end of its setup block:

path_template = rest

This assigns a local string variable with the exact same name as the enclosing function. In Python, a name is determined to be local to a function at compile time - if Python sees any assignment to path_template anywhere in the function body, the entire function body treats path_template as a local variable. This means the module-level function object is completely inaccessible inside path_template() after the assignment.

The specific code path is: the function splits the input template into path, query, and fragment portions (rest = template, then optional splits on # and ?), and then assigns path_template = rest to hold the path portion. This string is then passed to _interpolate(path_template, kwargs, _quote_path_segment_part) on the very next statement.

The existing code is safe only because: (1) the function is not recursive and does not need to call itself, and (2) the local variable path_template (the string) is only accessed on the line immediately following its assignment, strictly after it has been bound. There is no window where an UnboundLocalError can occur in the current code.

However, this is an error-prone pattern with real maintenance risks. If a developer later adds code inside this function body and writes path_template(...), Python will raise TypeError: 'str' object is not callable (if after the assignment) or UnboundLocalError: local variable 'path_template' referenced before assignment (if before). Both errors would be confusing because the name visually looks like a function reference. Static analysis tools like pyright also flag this shadowing.

Step-by-step proof:

  1. Call path_template("/v1/{id}", id="abc").
  2. Inside the function, rest = "/v1/{id}", no # or ?, so no splits occur.
  3. path_template = rest assigns the string "/v1/{id}" to the local name path_template.
  4. _interpolate(path_template, ...) uses the local string - works fine currently.
  5. If a developer adds path_template(sub_template, ...) anywhere in this function after this PR, they will get a runtime error instead of a function call, because Python has already marked path_template as a local variable for the entire function scope.

Fix: rename the local variable to path_str or path_portion and update the single usage on the next line:

path_str = rest
path_result = _interpolate(path_str, kwargs, _quote_path_segment_part)

@stainless-app stainless-app bot merged commit 178a9d7 into main Apr 1, 2026
5 checks passed
@stainless-app stainless-app bot deleted the release-please--branches--main--changes--next branch April 1, 2026 21:46
@stainless-app
Copy link
Copy Markdown
Contributor Author

stainless-app bot commented Apr 1, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant