Skip to content

fix(python): exclude unset API values on model dump #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/generation.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export const patterns = [
'clients/algoliasearch-client-python/requirements.txt',
'clients/algoliasearch-client-python/.gitignore',

'tests/output/python/requirements.txt',
'tests/output/python/poetry.lock',
'!tests/output/python/**/__init__.py',

Expand Down
21 changes: 18 additions & 3 deletions playground/python/app/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from asyncio import run
from os import environ
from base64 import b64decode

from algoliasearch.search.client import SearchClient
from algoliasearch.search.models.search_params_object import SearchParamsObject
from algoliasearch.search.models.secured_api_key_restrictions import (
SecuredApiKeyRestrictions,
)
from algoliasearch.search import __version__
from dotenv import load_dotenv

Expand All @@ -17,9 +22,19 @@ async def main():
print("client initialized", client)

try:
await client.browse_objects(
index_name="api-clients-automation",
aggregator=lambda _resp: print("baaaaaaaaaaaaaaar", _resp.to_json()),
# resp = await client.search(search_method_params={
# "requests": [{"indexName": "api-clients-automation"}]
# })
# print(resp.to_dict())
print(
b64decode(await client.generate_secured_api_key(
"foo",
SecuredApiKeyRestrictions(
restrictIndices=["foo"],
filters="bar",
searchParams=SearchParamsObject(attributesToRetrieve=["baz"]),
),
))
)
finally:
await client.close()
Expand Down
6 changes: 3 additions & 3 deletions playground/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion playground/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://www.algolia.com"
repository = "https://github.com/algolia/api-clients-automation"

[tool.poetry.dependencies]
python = "^3.8.1"
python = ">= 3.8.1"
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
ruff = "== 0.6.4"
python-dotenv = "== 1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion playground/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ argcomplete==3.5.0
click==8.1.7
packaging==24.1
pipx==1.7.1
platformdirs==4.3.3
platformdirs==4.2.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the downgrade ? I think this file should be excluded from PR

Copy link
Member Author

Choose a reason for hiding this comment

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

idk I've let the tooling do its thing, it was after this change

userpath==1.9.2
2 changes: 1 addition & 1 deletion scripts/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
break;
case 'python':
await run(
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix && poetry run ruff format',
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix --unsafe-fixes && poetry run ruff format',
{ cwd, language },
);
break;
Expand Down
3 changes: 2 additions & 1 deletion templates/python/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{/isAdditionalPropertiesTrue}}
},
exclude_none=True,
exclude_unset=True,
)
{{#allVars}}
{{#isContainer}}
Expand Down Expand Up @@ -329,4 +330,4 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}

{{/isAdditionalPropertiesTrue}}
return _obj
{{/hasChildren}}
{{/hasChildren}}
Loading