Skip to content

Commit ba745be

Browse files
authored
fix(python): exclude unset API values on model dump (#3777)
1 parent a62c27d commit ba745be

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

config/generation.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export const patterns = [
119119
'clients/algoliasearch-client-python/requirements.txt',
120120
'clients/algoliasearch-client-python/.gitignore',
121121

122-
'tests/output/python/requirements.txt',
123122
'tests/output/python/poetry.lock',
124123
'!tests/output/python/**/__init__.py',
125124

playground/python/app/search.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from asyncio import run
22
from os import environ
3+
from base64 import b64decode
34

45
from algoliasearch.search.client import SearchClient
6+
from algoliasearch.search.models.search_params_object import SearchParamsObject
7+
from algoliasearch.search.models.secured_api_key_restrictions import (
8+
SecuredApiKeyRestrictions,
9+
)
510
from algoliasearch.search import __version__
611
from dotenv import load_dotenv
712

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

1924
try:
20-
await client.browse_objects(
21-
index_name="api-clients-automation",
22-
aggregator=lambda _resp: print("baaaaaaaaaaaaaaar", _resp.to_json()),
25+
# resp = await client.search(search_method_params={
26+
# "requests": [{"indexName": "api-clients-automation"}]
27+
# })
28+
# print(resp.to_dict())
29+
print(
30+
b64decode(await client.generate_secured_api_key(
31+
"foo",
32+
SecuredApiKeyRestrictions(
33+
restrictIndices=["foo"],
34+
filters="bar",
35+
searchParams=SearchParamsObject(attributesToRetrieve=["baz"]),
36+
),
37+
))
2338
)
2439
finally:
2540
await client.close()

playground/python/poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homepage = "https://www.algolia.com"
99
repository = "https://github.com/algolia/api-clients-automation"
1010

1111
[tool.poetry.dependencies]
12-
python = "^3.8.1"
12+
python = ">= 3.8.1"
1313
algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true }
1414
ruff = "== 0.6.4"
1515
python-dotenv = "== 1.0.1"

playground/python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ argcomplete==3.5.0
22
click==8.1.7
33
packaging==24.1
44
pipx==1.7.1
5-
platformdirs==4.3.3
5+
platformdirs==4.2.2
66
userpath==1.9.2

scripts/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
5151
break;
5252
case 'python':
5353
await run(
54-
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix && poetry run ruff format',
54+
'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run ruff check --fix --unsafe-fixes && poetry run ruff format',
5555
{ cwd, language },
5656
);
5757
break;

templates/python/model_generic.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
124124
{{/isAdditionalPropertiesTrue}}
125125
},
126126
exclude_none=True,
127+
exclude_unset=True,
127128
)
128129
{{#allVars}}
129130
{{#isContainer}}
@@ -329,4 +330,4 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
329330

330331
{{/isAdditionalPropertiesTrue}}
331332
return _obj
332-
{{/hasChildren}}
333+
{{/hasChildren}}

0 commit comments

Comments
 (0)