-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: support classes #5079
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
feat: support classes #5079
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Import Logic Causes Unpredictable Name Collisions
The Python provider's new import logic introduces silent name collisions. When multiple modules are imported, public attributes (classes, functions, variables) with identical names from later modules silently overwrite those from earlier modules in the loaded_modules dictionary. This leads to unpredictable behavior, as the wrong function or class may be used (e.g., sys.path overwriting os.path), making code unreliable and difficult to debug.
keep/providers/python_provider/python_provider.py#L33-L42
keep/keep/providers/python_provider/python_provider.py
Lines 33 to 42 in 01bcfb6
| if modules: | |
| for module in modules.split(","): | |
| try: | |
| imported_module = __import__(module, fromlist=[""]) | |
| # Add all public attributes from the module to loaded_modules | |
| for attr_name in dir(imported_module): | |
| if not attr_name.startswith("_"): | |
| loaded_modules[attr_name] = getattr( | |
| imported_module, attr_name | |
| ) |
Bug: Production Code Contaminated with Debug Code
The if __name__ == "__main__": block introduces unintended debug/test code into the production codebase. This includes debug logging, hardcoded context and provider instantiation, and an example query execution.
keep/providers/python_provider/python_provider.py#L61-L83
keep/keep/providers/python_provider/python_provider.py
Lines 61 to 83 in 01bcfb6
| if __name__ == "__main__": | |
| # Example usage | |
| # Output debug messages | |
| import logging | |
| from keep.providers.providers_factory import ProvidersFactory | |
| logging.basicConfig(level=logging.DEBUG, handlers=[logging.StreamHandler()]) | |
| context_manager = ContextManager( | |
| tenant_id="singletenant", | |
| workflow_id="test", | |
| ) | |
| python_provider = ProvidersFactory.get_provider( | |
| context_manager=context_manager, | |
| provider_id="python-keephq", | |
| provider_type="python", | |
| provider_config={"authentication": {}}, | |
| ) | |
| # Example query | |
| result = python_provider._query(code="1 + 1", imports="keep.api.models.alert") | |
| print(result) # Output: 2 |
Was this report helpful? Give feedback by reacting with 👍 or 👎
close #5078