Skip to content

[WEB-4088] fix: issue exports when cycles are not present#7057

Merged
pushya22 merged 2 commits intopreviewfrom
optimize-issue-exports
May 14, 2025
Merged

[WEB-4088] fix: issue exports when cycles are not present#7057
pushya22 merged 2 commits intopreviewfrom
optimize-issue-exports

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented May 14, 2025

Description

  • issue exports when cycles are not present
  • added doc strings and types

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (change that would cause existing functionality to not work as expected)

Test Scenarios

  • export for multiple projects using different providers (csv, xlsx, json)

References

WEB-4088

Summary by CodeRabbit

  • Refactor
    • Improved clarity and consistency in data export processes, including enhanced handling of assignees, labels, and cycle data.
    • Refined attachment export logic for more accurate results.
  • Style
    • Added detailed descriptions and type annotations to various export-related functions for improved readability and maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 14, 2025

Walkthrough

This change introduces explicit type annotations and detailed docstrings to all major functions in the export task module. It refactors helper logic for extracting creator names, improves attachment and cycle data handling, and corrects data update logic for assignees and labels. Export provider mappings are made explicit.

Changes

File(s) Change Summary
apiserver/plane/bgtasks/export_task.py Added type annotations and docstrings to all functions; introduced get_created_by helper; refined attachment and cycle data extraction; corrected assignee/label update logic; clarified export provider mapping; updated function signatures for type safety and clarity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExportTask
    participant FileAssetDB
    participant S3
    participant Exporter

    User->>ExportTask: Trigger issue_export_task(provider, workspace_id, ...)
    ExportTask->>FileAssetDB: Query issue attachments (entity_type=ISSUE_ATTACHMENT)
    ExportTask->>Exporter: Generate export file (CSV/JSON/XLSX)
    Exporter->>ExportTask: Return generated file
    ExportTask->>S3: Upload export file to S3
    ExportTask-->>User: Export task completion
Loading

Possibly related PRs

Suggested labels

🐛bug, ⚙️backend, ready_to_merge

Poem

In the warren of code, where the exports hop,
Type hints and docstrings now never stop.
Attachments are sorted, creators named right,
Assignees and labels all tucked in tight.
With mappings so clear, and bugs out of sight,
This rabbit’s export task is now pure delight!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81494e5 and 6aa3e4f.

📒 Files selected for processing (1)
  • apiserver/plane/bgtasks/export_task.py (17 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apiserver/plane/bgtasks/export_task.py (2)
apiserver/plane/db/models/issue.py (2)
  • Issue (104-253)
  • IssueComment (455-493)
apiserver/plane/utils/exception_logger.py (1)
  • log_exception (9-18)
🪛 Ruff (0.8.2)
apiserver/plane/bgtasks/export_task.py

94-94: Line too long (93 > 88)

(E501)


205-205: Line too long (96 > 88)

(E501)


311-311: Line too long (119 > 88)

(E501)


323-323: Line too long (120 > 88)

(E501)


335-335: Line too long (120 > 88)

(E501)


358-358: Line too long (123 > 88)

(E501)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CodeQL
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (10)
apiserver/plane/bgtasks/export_task.py (10)

6-10: Added proper imports for type annotations

Good addition of typing imports to support the explicit type annotations throughout the file.


44-93: Improved function signatures with types and documentation

Good addition of typed parameters and return values with descriptive docstrings for all utility functions. This enhances code readability and helps with type checking.


179-218: Fixed cycle data access in table row generation

Good change to directly access cycle-related fields instead of using .get() with defaults, reflecting the guaranteed presence of these fields after issue data construction in issue_export_task.

🧰 Tools
🪛 Ruff (0.8.2)

205-205: Line too long (96 > 88)

(E501)


348-354: Added helper function for creator name extraction

Excellent addition of the get_created_by helper function to centralize and standardize the extraction of creator names from both Issue and IssueComment objects. This improves code maintainability.


411-412: Improved attachment filtering

Good addition of entity type filtering to specifically target issue attachments, making the query more precise and efficient.


445-452: Refactored creator name extraction

Good use of the new get_created_by helper function to standardize name formatting across issues and comments.


472-481: Fixed issue exports when cycles are not present

This change properly handles the case when an issue has no associated cycle by providing empty strings for cycle-related fields, addressing the main bug from PR objectives.


515-519: Added explicit export provider mapping

Good use of a dictionary to map export providers to their respective functions, improving code clarity and maintainability.


311-345: Properly typed export generation functions

Good addition of explicit type annotations to the export generation functions, making the code more maintainable and easier to understand.

🧰 Tools
🪛 Ruff (0.8.2)

311-311: Line too long (119 > 88)

(E501)


323-323: Line too long (120 > 88)

(E501)


335-335: Line too long (120 > 88)

(E501)


358-364: Enhanced main export task with proper typing

The addition of type hints and detailed docstrings to the main export task improves its clarity and maintainability. The function signature now clearly communicates expected parameter types.

🧰 Tools
🪛 Ruff (0.8.2)

358-358: Line too long (123 > 88)

(E501)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@makeplane
Copy link

makeplane bot commented May 14, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (2)
apiserver/plane/bgtasks/export_task.py (2)

254-282: ⚠️ Potential issue

update_json_row merges the wrong fields and breaks on list ⇄ string mismatches

  • Compares label not in existing_assignees, clearly a copy-paste error.
  • Tries to concatenate list (assignee) to str, raising TypeError.
  • Assignees / labels are lists in the source row – treat them as such.
-        existing_assignees, existing_labels = (
-            rows[matched_index]["Assignee"],
-            rows[matched_index]["Labels"],
-        )
-        assignee, label = row["Assignee"], row["Labels"]
-
-        if assignee is not None and (
-            existing_assignees is None or label not in existing_assignees
-        ):
-            rows[matched_index]["Assignee"] += f", {assignee}"
-        if label is not None and (
-            existing_labels is None or label not in existing_labels
-        ):
-            rows[matched_index]["Labels"] += f", {label}"
+        existing_assignees = set(rows[matched_index].get("Assignee", []))
+        existing_labels    = set(rows[matched_index].get("Labels", []))
+
+        new_assignees = set(row.get("Assignee", []))
+        new_labels    = set(row.get("Labels", []))
+
+        rows[matched_index]["Assignee"] = sorted(existing_assignees | new_assignees)
+        rows[matched_index]["Labels"]   = sorted(existing_labels    | new_labels)

286-308: 🛠️ Refactor suggestion

update_table_row uses wrong column indexes (priority / created-by instead of labels / assignees)

Column layout from generate_table_row:

… 8 = Created By, 9 = Labels, …, 21 = Assignees …

Current slice rows[matched_index][7:9] captures Priority & Created By, not Assignees & Labels.
Updating the wrong columns silently corrupts exported data.

-        existing_assignees, existing_labels = rows[matched_index][7:9]
-        assignee, label = row[7:9]
+        existing_assignees = rows[matched_index][21]
+        existing_labels    = rows[matched_index][9]
+        assignee           = row[21]
+        label              = row[9]
@@
-            rows[matched_index][8] += f", {assignee}"
+            rows[matched_index][21] = ", ".join(
+                sorted(set(filter(None, existing_assignees.split(", ")) | set(filter(None, assignee.split(", ")))))
+            )
@@
-            rows[matched_index][8] += f", {label}"
+            rows[matched_index][9] = ", ".join(
+                sorted(set(filter(None, existing_labels.split(", ")) | set(filter(None, label.split(", ")))))
+            )
🧹 Nitpick comments (2)
apiserver/plane/bgtasks/export_task.py (2)

86-89: Possible encoding issue when archiving text files

zipfile.writestr() treats a str as DOS-encoded CP437 bytes, which mangles any non-ASCII character in CSV/JSON contents.
Convert strings to UTF-8 bytes before writing:

-        for filename, file_content in files:
-            zipf.writestr(filename, file_content)
+        for filename, file_content in files:
+            if isinstance(file_content, str):
+                file_content = file_content.encode("utf-8")
+            zipf.writestr(filename, file_content)

348-355: Minor: avoid creating " " when only one name part exists

get_created_by will return "John " (trailing space) if last_name is empty.
Tiny nit, but trimming avoids cosmetic artifacts in exports.

-        return f"{obj.created_by.first_name} {obj.created_by.last_name}"
+        full_name = f"{obj.created_by.first_name} {obj.created_by.last_name}".strip()
+        return full_name
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 080cf70 and 81494e5.

📒 Files selected for processing (1)
  • apiserver/plane/bgtasks/export_task.py (17 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/bgtasks/export_task.py

94-94: Line too long (93 > 88)

(E501)


205-205: Line too long (96 > 88)

(E501)


311-311: Line too long (119 > 88)

(E501)


323-323: Line too long (120 > 88)

(E501)


335-335: Line too long (120 > 88)

(E501)


358-358: Line too long (123 > 88)

(E501)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)

@dheeru0198 dheeru0198 self-requested a review May 14, 2025 11:43
@pushya22 pushya22 merged commit 534f5c7 into preview May 14, 2025
4 of 6 checks passed
@pushya22 pushya22 deleted the optimize-issue-exports branch May 14, 2025 12:30
al-jaber-nishad pushed a commit to Xinotrix-Home/task-and-meeting-management that referenced this pull request May 27, 2025
…7057)

* fix: issue exports when cycles are not present

* fix: type check
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* fix: issue exports when cycles are not present

* fix: type check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants