Significant-Gravitas / AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
https://agpt.co
Other
174.63k stars 45.59k forks source link

feat(backend): Fix failed RPC on Notification Service #9630

Closed majdyz closed 1 month ago

majdyz commented 1 month ago

Although returning a Prisma object on an RPC is a bad practice, we have instances where we do so and the type contains a prisma.Json field. This Json field can't be seamlessly serialized and then converted back into the Prisma object.

Changes πŸ—οΈ

Replacing prisma object as return type on notification service with a plain pydantic object as DTO.

Checklist πŸ“‹

For code changes:

qodo-merge-pro[bot] commented 1 month ago

PR Reviewer Guide πŸ”

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 πŸ”΅πŸ”΅πŸ”΅βšͺβšͺ
πŸ§ͺ No relevant tests
πŸ”’ No security concerns identified
⚑ Recommended focus areas for review

Potential Recursion Issue The transformation logic handles recursive types but might still encounter issues with deeply nested or complex type structures. Consider adding a maximum recursion depth limit as a safeguard. ```python def _transform_type_recursive(tp: Any, local_cache: dict[Any, Any]) -> Any: """ Does the actual recursion: - If `tp` is in `GLOBAL_REPLACEMENTS`, use that replacement. - If it's a Pydantic model, build a new model with replaced field types. - If it's a container (list, tuple, Union, etc.), transform each argument. - Otherwise, return as-is. """ if tp in local_cache: # Already transformed (or in process); return it return local_cache[tp] # If exactly in the global replacements, do a direct swap if tp in GLOBAL_REPLACEMENTS: replaced = GLOBAL_REPLACEMENTS[tp] local_cache[tp] = replaced return replaced ```
Cache Management The global cache (_GLOBAL_TYPE_TRANSFORM_CACHE) grows unbounded without any mechanism to clear it. Consider adding a cache size limit or a way to invalidate entries. ```python _GLOBAL_TYPE_TRANSFORM_CACHE: dict[Any, Any] = {} ```
Type Preservation When transforming Pydantic models, field validators, config settings, and other model metadata might be lost. Verify if this is acceptable for the use case. ```python def _transform_model( model_cls: type[BaseModel], local_cache: dict[Any, Any] ) -> type[BaseModel]: """ Build a new Pydantic model that mirrors `model_cls` but with replaced field types. Prevent infinite recursion with local_cache placeholders. """ # If we've started building this model in the recursion, return immediately if model_cls in local_cache and local_cache[model_cls] is None: return model_cls # Mark as 'in progress' with None local_cache[model_cls] = None # Build new fields field_defs = {} for field_name, field_info in model_cls.model_fields.items(): old_annotation = field_info.annotation new_annotation = _transform_type_recursive(old_annotation, local_cache) if field_info.is_required(): default_val = ... else: default_val = field_info.default field_defs[field_name] = (new_annotation, default_val) new_name = f"{model_cls.__name__}Transformed" NewModel = create_model( new_name, __base__=BaseModel, **field_defs, ) local_cache[model_cls] = NewModel return NewModel ```
netlify[bot] commented 1 month ago

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
Latest commit 611759bf92558655d39bce17b0688bc1972d11ba
Latest deploy log https://app.netlify.com/sites/auto-gpt-docs-dev/deploys/67d37e5a7122de00081e8f55
deepsource-io[bot] commented 1 month ago

Here's the code health analysis summary for commits f4d4bb8..611759b. View details on DeepSource β†—.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScriptβœ… SuccessView Check β†—
DeepSource Python LogoPythonβœ… SuccessView Check β†—

πŸ’‘ If you’re a repository administrator, you can configure the quality gates from the settings.
netlify[bot] commented 1 month ago

Deploy Preview for auto-gpt-docs canceled.

Name Link
Latest commit 611759bf92558655d39bce17b0688bc1972d11ba
Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/67d37e5adb6ec50008ec26fb
AutoGPT-Agent commented 1 month ago

The PR is well-structured but missing some critical elements. While the description explains the technical need and solution, and includes tested changes, the checklist is incomplete (the example test plan section is still visible and not removed as allowed by rules). Additionally, the PR title follows the conventional commit format correctly with feat(backend). The changes don't appear to involve data/*.py files or frontend routes, so those rules aren't applicable. The changes seem reasonable and well-tested for their scope.

AutoGPT-Agent commented 1 month ago

The PR is missing key information and has potential issues: 1) The title has a scope but it doesn't match what's actually being changed (notifications, not just backend). 2) The test plan is very minimal given the complexity of the notification system changes. 3) There are data/*.py changes where we need to verify user_id handling which isn't addressed. However, looking at the code it appears the user_id is being handled properly in the notification DTOs and the changes appear to be maintaining proper access controls.