dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
223 stars 125 forks source link

RecursionError: maximum recursion depth exceeded while calling a Python object #539

Closed ryou90 closed 1 year ago

ryou90 commented 1 year ago

Expected Behavior

I want to retrieve an env variable from the dapr.config.settings class. If the variable is not present, an attribute error should be issued.

E.g.

from dapr.conf import settings

x = settings.APP_PORT # Not exist -> throw recursion error

Actual Behavior

When the variable not exists, a maximum recursion error is thrown and not a attribute error. This happens because the settings class use getattr method to lookup for non existing env variables. Within the method, getattr(..) is called, which caused a new recursive call.

The problem can be easily solved by removing the getattr method.

Steps to Reproduce the Problem

Test example code.

Release Note

RELEASE NOTE: Fix RecursionError when calling non-existing env variable from settings class

berndverst commented 1 year ago

APP_PORT is not a supported setting in this SDK. There is HTTP_APP_PORT and GRPC_APP_PORT.

See https://github.com/dapr/python-sdk/blob/a1aa2cb17a7c16c3e5091c915ca48baeaea95910/dapr/conf/global_settings.py#L18-L29

I updated the open PR for this issue to instead throw an AttributeError whenever you try to access a property that is not implemented.

EDIT: Your issue was filed correctly - I got confused because I looked at the PR that was opened first (thought it was from you, but was from someone else). The updates I made to that PR should give you exactly what you want -- an AttributeError for properties that don't exist / are not supported.