Skip to content

Conversation

shahargl
Copy link
Member

close #5078

@vercel
Copy link

vercel bot commented Jun 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
keep ⬜️ Ignored (Inspect) Jun 23, 2025 11:45am

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Feature A new feature labels Jun 23, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 23, 2025
@shahargl shahargl merged commit 4472e9c into main Jun 23, 2025
18 of 19 checks passed
@shahargl shahargl deleted the feature/modules branch June 23, 2025 11:46
Copy link

@cursor cursor bot left a 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

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
)

Fix in Cursor


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

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

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature A new feature lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[➕ Feature]: support classes on python provider

2 participants