Skip to content

Commit a28b3ed

Browse files
committed
feat(connection, application_name): set to calling module if unspecified
1 parent 701f6e9 commit a28b3ed

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

redshift_connector/core.py

+24
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,30 @@ def __init__(
502502

503503
redshift_native_auth: bool = False
504504

505+
if application_name is None or application_name == "":
506+
507+
def get_calling_module() -> str:
508+
import inspect
509+
510+
module_name: str = ""
511+
stack: typing.List[inspect.FrameInfo] = inspect.stack()
512+
try:
513+
# get_calling_module -> init -> connect -> init -> calling module
514+
start: int = min(4, len(stack) - 1)
515+
parent = stack[start][0]
516+
calling_module = inspect.getmodule(parent)
517+
518+
if calling_module:
519+
module_name = calling_module.__name__
520+
except:
521+
pass
522+
finally:
523+
del parent
524+
del stack
525+
526+
return module_name
527+
528+
application_name = get_calling_module()
505529
init_params: typing.Dict[str, typing.Optional[typing.Union[str, bytes]]] = {
506530
"user": "",
507531
"database": database,

0 commit comments

Comments
 (0)