Skip to content
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

Missing comma breaks cosmos.azure.aio.CosmosClient.from_connection_string() #22514

Closed
taybin opened this issue Jan 14, 2022 · 6 comments
Closed
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@taybin
Copy link

taybin commented Jan 14, 2022

  • Package Name: azure-cosmos
  • Package Version: 4.3.0b1
  • Operating System:
  • Python Version: 3.9

Describe the bug
A comma is missing at the end of line 162:

return cls(
url=settings['AccountEndpoint'],
credential=credential or settings['AccountKey'],
consistency_level=kwargs.get('consistency_level', 'Session')
**kwargs
)

This results in python trying to use the ** operator on a string and a dict and it throws an exception.

To Reproduce

  1. Call the function cosmos.aure.aio.CosmosClient.from_connection_string()

Expected behavior
The function should not throw an exception

Additional context
Full stack trace:

[2022-01-14T19:46:15.342Z] Exception: TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'dict'
[2022-01-14T19:46:15.342Z] Stack:   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/dis
patcher.py", line 305, in _handle__function_load_request
[2022-01-14T19:46:15.342Z]     func = loader.load_function(
[2022-01-14T19:46:15.342Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/utils/wrap
pers.py", line 40, in call
[2022-01-14T19:46:15.342Z]     return func(*args, **kwargs)
[2022-01-14T19:46:15.342Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/loader.py"
, line 85, in load_function
[2022-01-14T19:46:15.342Z]     mod = importlib.import_module(fullmodname)
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/.asdf/installs/python/3.9.7/lib/python3.9/importlib/__init__.py", line 127, in import_module
[2022-01-14T19:46:15.342Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/src/udm_v2/src/function_apps/projection_handler/projection_handler/__init__.py", line 35, in <module>
[2022-01-14T19:46:15.342Z]     cosmos_client = CosmosClient.from_connection_string(DOCUMENTDB_CONNSTR)
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/src/udm_v2/src/function_apps/projection_handler/.venv/lib/python3.9/site-packages/azure/cosmos/aio/co
smos_client.py", line 180, in from_connection_string
[2022-01-14T19:46:15.342Z]     consistency_level=kwargs.get("consistency_level", "Session") ** kwargs,
[2022-01-14T19:46:15.342Z] .

Running a linter on python code is very helpful for catching these sort of issues.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 14, 2022
@mccoyp
Copy link
Member

mccoyp commented Jan 14, 2022

Hi @taybin, thank you for opening an issue! I'll tag the appropriate folks so we can look into this as soon as possible.

@mccoyp mccoyp added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Jan 14, 2022
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jan 14, 2022
@Rodrigossz Rodrigossz assigned gahl-levy and unassigned Rodrigossz Jan 14, 2022
@simorenoh
Copy link
Member

Hi @taybin, thank you for pointing this out, a PR has been made to take care of this and should be released soon: #22536

Since you're testing out our async client, do let us know if you run into anything else so we can take a look! Hope you have a nice day!

@stevesimmons
Copy link

Do both this from_connection_string method and azure.cosmos.aio.cosmos_client.CosmosClient() need another fix?

If kwargs in both these methods contain the key consistency_level, the constructor to CosmosClientConnection(...) will get this argument twice, once as consistency_level and again in kwargs. To fix this, L116 and L162 should probably replace kwargs.get with kwargs.pop.

@simorenoh
Copy link
Member

Hi @stevesimmons,

I see what you mean, and this is something we plan to take care of as a future effort. Python3 best practices insist on not using kwargs for most arguments being passed into functions, and to align with this we will be making those changes soon (specially for the async client since it's new). We have an issue created to track this effort. Thank you for pointing this out!

@PramodValavala-MSFT PramodValavala-MSFT added Service Attention Workflow: This issue is responsible by Azure service team. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team CXP Attention labels Feb 9, 2022
@ghost
Copy link

ghost commented Feb 9, 2022

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @simorenoh, @gahl-levy.

Issue Details
  • Package Name: azure-cosmos
  • Package Version: 4.3.0b1
  • Operating System:
  • Python Version: 3.9

Describe the bug
A comma is missing at the end of line 162:

return cls(
url=settings['AccountEndpoint'],
credential=credential or settings['AccountKey'],
consistency_level=kwargs.get('consistency_level', 'Session')
**kwargs
)

This results in python trying to use the ** operator on a string and a dict and it throws an exception.

To Reproduce

  1. Call the function cosmos.aure.aio.CosmosClient.from_connection_string()

Expected behavior
The function should not throw an exception

Additional context
Full stack trace:

[2022-01-14T19:46:15.342Z] Exception: TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'dict'
[2022-01-14T19:46:15.342Z] Stack:   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/dis
patcher.py", line 305, in _handle__function_load_request
[2022-01-14T19:46:15.342Z]     func = loader.load_function(
[2022-01-14T19:46:15.342Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/utils/wrap
pers.py", line 40, in call
[2022-01-14T19:46:15.342Z]     return func(*args, **kwargs)
[2022-01-14T19:46:15.342Z]   File "/usr/local/Cellar/azure-functions-core-tools@4/4.0.3971/workers/python/3.9/OSX/X64/azure_functions_worker/loader.py"
, line 85, in load_function
[2022-01-14T19:46:15.342Z]     mod = importlib.import_module(fullmodname)
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/.asdf/installs/python/3.9.7/lib/python3.9/importlib/__init__.py", line 127, in import_module
[2022-01-14T19:46:15.342Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
[2022-01-14T19:46:15.342Z]   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/src/udm_v2/src/function_apps/projection_handler/projection_handler/__init__.py", line 35, in <module>
[2022-01-14T19:46:15.342Z]     cosmos_client = CosmosClient.from_connection_string(DOCUMENTDB_CONNSTR)
[2022-01-14T19:46:15.342Z]   File "/Users/trutkin/src/udm_v2/src/function_apps/projection_handler/.venv/lib/python3.9/site-packages/azure/cosmos/aio/co
smos_client.py", line 180, in from_connection_string
[2022-01-14T19:46:15.342Z]     consistency_level=kwargs.get("consistency_level", "Session") ** kwargs,
[2022-01-14T19:46:15.342Z] .

Running a linter on python code is very helpful for catching these sort of issues.

Author: taybin
Assignees: simorenoh, gahl-levy
Labels:

bug, Cosmos, Service Attention, Client, customer-reported

Milestone: -

@PramodValavala-MSFT
Copy link
Contributor

@taybin This has been fixed in #22536. Closing.

@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Feb 9, 2022
@PramodValavala-MSFT PramodValavala-MSFT removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Feb 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

7 participants