Skip to content

Commit 796d801

Browse files
authored
[SchemaRegistry] fix logging_enable bug (Azure#21488)
* move kwarg * adams comments * move to helper * update samples/tests with logging * remove from samples
1 parent 7459dab commit 796d801

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_schema_registry_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# --------------------------------------------------------------------------
2626
from typing import Any, TYPE_CHECKING, Union
2727

28+
from ._utils import get_http_request_kwargs
2829
from ._common._constants import SchemaFormat
2930
from ._common._schema import Schema, SchemaProperties
3031
from ._common._response_handlers import (
@@ -114,16 +115,17 @@ def register_schema(
114115
except AttributeError:
115116
pass
116117

118+
http_request_kwargs = get_http_request_kwargs(kwargs)
117119
request = schema_rest.build_register_request(
118120
group_name=group_name,
119121
schema_name=name,
120122
content=schema_definition,
121123
serialization_type=format,
122124
content_type=kwargs.pop("content_type", "application/json"),
123-
**kwargs
125+
**http_request_kwargs
124126
)
125127

126-
response = self._generated_client.send_request(request)
128+
response = self._generated_client.send_request(request, **kwargs)
127129
response.raise_for_status()
128130
return _parse_response_schema_properties(response)
129131

@@ -147,7 +149,8 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
147149
:caption: Get schema by id.
148150
149151
"""
150-
request = schema_rest.build_get_by_id_request(schema_id=id)
152+
http_request_kwargs = get_http_request_kwargs(kwargs)
153+
request = schema_rest.build_get_by_id_request(schema_id=id, **http_request_kwargs)
151154
response = self._generated_client.send_request(request, **kwargs)
152155
response.raise_for_status()
153156
return _parse_response_schema(response)
@@ -183,13 +186,14 @@ def get_schema_properties(
183186
except AttributeError:
184187
pass
185188

189+
http_request_kwargs = get_http_request_kwargs(kwargs)
186190
request = schema_rest.build_query_id_by_content_request(
187191
group_name=group_name,
188192
schema_name=name,
189193
content=schema_definition,
190194
serialization_type=format,
191195
content_type=kwargs.pop("content_type", "application/json"),
192-
**kwargs
196+
**http_request_kwargs
193197
)
194198

195199
response = self._generated_client.send_request(request, **kwargs)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
def get_http_request_kwargs(kwargs):
7+
http_request_keywords = ["params", "headers", "json", "data", "files"]
8+
http_request_kwargs = {key: kwargs.pop(key, None) for key in http_request_keywords if key in kwargs}
9+
return http_request_kwargs

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/aio/_schema_registry_client_async.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# --------------------------------------------------------------------------
2626
from typing import Any, TYPE_CHECKING, Union
2727

28+
from .._utils import get_http_request_kwargs
2829
from .._common._constants import SchemaFormat
2930
from .._common._schema import Schema, SchemaProperties
3031
from .._common._response_handlers import (
@@ -116,16 +117,17 @@ async def register_schema(
116117
except AttributeError:
117118
pass
118119

120+
http_request_kwargs = get_http_request_kwargs(kwargs)
119121
request = schema_rest.build_register_request(
120122
group_name=group_name,
121123
schema_name=name,
122124
content=schema_definition,
123125
serialization_type=format,
124126
content_type=kwargs.pop("content_type", "application/json"),
125-
**kwargs
127+
**http_request_kwargs
126128
)
127129

128-
response = await self._generated_client.send_request(request)
130+
response = await self._generated_client.send_request(request, **kwargs)
129131
response.raise_for_status()
130132
return _parse_response_schema_properties(response)
131133

@@ -152,7 +154,8 @@ async def get_schema(
152154
:caption: Get schema by id.
153155
154156
"""
155-
request = schema_rest.build_get_by_id_request(schema_id=id)
157+
http_request_kwargs = get_http_request_kwargs(kwargs)
158+
request = schema_rest.build_get_by_id_request(schema_id=id, **http_request_kwargs)
156159
response = await self._generated_client.send_request(request, **kwargs)
157160
response.raise_for_status()
158161
return _parse_response_schema(response)
@@ -192,13 +195,14 @@ async def get_schema_properties(
192195
except AttributeError:
193196
pass
194197

198+
http_request_kwargs = get_http_request_kwargs(kwargs)
195199
request = schema_rest.build_query_id_by_content_request(
196200
group_name=group_name,
197201
schema_name=name,
198202
content=schema_definition,
199203
serialization_type=format,
200204
content_type=kwargs.pop("content_type", "application/json"),
201-
**kwargs
205+
**http_request_kwargs
202206
)
203207

204208
response = await self._generated_client.send_request(request, **kwargs)

sdk/schemaregistry/azure-schemaregistry/tests/async_tests/test_schema_registry_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ async def test_schema_basic_async(self, schemaregistry_fully_qualified_namespace
4747
schema_name = self.get_resource_name('test-schema-basic-async')
4848
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
4949
format = "Avro"
50-
schema_properties = await client.register_schema(schemaregistry_group, schema_name, schema_str, format)
50+
schema_properties = await client.register_schema(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)
5151

5252
assert schema_properties.id is not None
5353
assert schema_properties.version is 1
5454
assert schema_properties.format == "Avro"
5555

56-
returned_schema = await client.get_schema(id=schema_properties.id)
56+
returned_schema = await client.get_schema(id=schema_properties.id, logging_enable=True)
5757

5858
assert returned_schema.properties.id == schema_properties.id
5959
assert returned_schema.properties.version == 1
6060
assert returned_schema.properties.format == "Avro"
6161
assert returned_schema.schema_definition == schema_str
6262

63-
returned_schema_properties = await client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format)
63+
returned_schema_properties = await client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)
6464

6565
assert returned_schema_properties.id == schema_properties.id
6666
assert returned_schema_properties.version == 1

sdk/schemaregistry/azure-schemaregistry/tests/test_schema_registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ def test_schema_basic(self, schemaregistry_fully_qualified_namespace, schemaregi
4242
schema_name = self.get_resource_name('test-schema-basic')
4343
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
4444
format = "Avro"
45-
schema_properties = client.register_schema(schemaregistry_group, schema_name, schema_str, format)
45+
schema_properties = client.register_schema(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)
4646

4747
assert schema_properties.id is not None
4848
assert schema_properties.version is 1
4949
assert schema_properties.format == "Avro"
5050

51-
returned_schema = client.get_schema(id=schema_properties.id)
51+
returned_schema = client.get_schema(id=schema_properties.id, logging_enable=True)
5252

5353
assert returned_schema.properties.id == schema_properties.id
5454
assert returned_schema.properties.version == 1
5555
assert returned_schema.properties.format == "Avro"
5656
assert returned_schema.schema_definition == schema_str
5757

58-
returned_schema_properties = client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format)
58+
returned_schema_properties = client.get_schema_properties(schemaregistry_group, schema_name, schema_str, format, logging_enable=True)
5959

6060
assert returned_schema_properties.id == schema_properties.id
6161
assert returned_schema_properties.version == 1

0 commit comments

Comments
 (0)