Skip to content

fix: rstrip error #1950

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix: rstrip error #1950

wants to merge 1 commit into from

Conversation

Rad710
Copy link

@Rad710 Rad710 commented Jul 22, 2025

User description

Fix error in gitlab when doing describe command:

2025-07-22 19:54:48.831 | INFO | pr_agent.tools.pr_description:extend_uncovered_files:375 - Adding 1 unprocessed extra files to table prediction 2025-07-22 19:54:48.838 | WARNING | pr_agent.tools.pr_description:_prepare_file_labels:645 - Empty changes summary in file label dict, skipping file 2025-07-22 19:54:48.839 | ERROR | pr_agent.tools.pr_description:run:197 - Error generating PR description https://gitlab.com/hispydevelopteam/his_internacion/-/merge_requests/452: 'dict' object has no attribute 'rstrip'


PR Type

Bug fix


Description

  • Fix AttributeError when processing non-string values in PR description

  • Add type checking for rstrip() method availability

  • Handle mixed data types in list processing


Diagram Walkthrough

flowchart LR
  A["List with mixed types"] --> B["Type checking"] --> C["Safe string conversion"] --> D["Apply rstrip() only to strings"]
Loading

File Walkthrough

Relevant files
Bug fix
pr_description.py
Fix rstrip AttributeError for mixed data types                     

pr_agent/tools/pr_description.py

  • Add hasattr(v, 'rstrip') check before calling rstrip() method
  • Convert non-string values to string using str(v) before processing
  • Apply fix to both description and general value processing sections
+4/-2     

Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
✅ No TODO sections
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Issue

The fix applies str() conversion twice - once in the conditional and once as fallback, which is redundant and could mask the original data type information that might be needed elsewhere.

    value = ', '.join(str(v).rstrip() if hasattr(v, 'rstrip') else str(v) for v in value)
value = value.replace('\n-', '\n\n-').strip() # makes the bullet points more readable by adding double space
Code Duplication

The same type checking and string conversion logic is duplicated in two places. Consider extracting this into a helper function to improve maintainability.

        value = ', '.join(str(v).rstrip() if hasattr(v, 'rstrip') else str(v) for v in value)
    value = value.replace('\n-', '\n\n-').strip() # makes the bullet points more readable by adding double space
    pr_body += f"{value}\n"
else:
    # if the value is a list, join its items by comma
    if isinstance(value, list):
        # Handle both strings and dictionaries in the list
        value = ', '.join(str(v).rstrip() if hasattr(v, 'rstrip') else str(v) for v in value)

Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Remove redundant hasattr check

The condition hasattr(v, 'rstrip') is redundant since str(v) always returns a
string object which has the rstrip method. This creates unnecessary complexity
and potential performance overhead.

pr_agent/tools/pr_description.py [613]

-value = ', '.join(str(v).rstrip() if hasattr(v, 'rstrip') else str(v) for v in value)
+value = ', '.join(str(v).rstrip() for v in value)
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that the hasattr(v, 'rstrip') check is redundant, as str(v) always returns a string which has an rstrip method, and simplifying the expression improves code clarity.

Low
  • More
  • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

@mrT23
Copy link
Collaborator

mrT23 commented Jul 23, 2025

I am not sure this solves the problem.
If the model outputs invalid content, than it cannot be parsed properly, and the output will be wierd.

How did it happen ? which model are you using ? Is it reproducable ?

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

Successfully merging this pull request may close these issues.

2 participants