Skip to content

Conversation

@harshtandiya
Copy link
Collaborator

@harshtandiya harshtandiya commented Jan 8, 2026

Summary by CodeRabbit

  • New Features

    • The "User Forms" module is now automatically created during installation, providing immediate access to form management.
  • Chores

    • Installation/upgrade flow updated to run post-install setup so the module is ensured to exist without manual steps.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

Activates the app's after_install hook, adds installation logic to create a "User Forms" Module Def, registers a pre_model_sync patch, and provides a patch script to create the module for existing sites; also skips two tests via unittest decorators.

Changes

Cohort / File(s) Summary
Hook Activation
forms_pro/hooks.py
Enabled after_install = "forms_pro.install.after_install" (was commented).
Module Creation Logic
forms_pro/install.py
Added after_install() and create_user_forms_module() to insert a Module Def for "User Forms" (app "Forms Pro") if missing.
Patch Registration
forms_pro/patches.txt
Added forms_pro.patches.0_1_beta.create_user_forms_module_def to pre_model_sync.
Patch Script
forms_pro/patches/0_1_beta/create_user_forms_module_def.py
New wrapper patch that imports and calls create_user_forms_module() via execute().
Tests
forms_pro/utils/test_form_generator.py
Decorated two test methods with @unittest.skip to skip them during runs.

Sequence Diagram(s)

sequenceDiagram
    actor Installer
    participant hooks.py as Hooks
    participant install.py as InstallLogic
    participant DB as ModuleDef (DB)

    Installer->>Hooks: trigger after_install hook
    Hooks->>InstallLogic: call after_install()
    InstallLogic->>DB: check for "User Forms" Module Def
    alt not found
        InstallLogic->>DB: insert Module Def ("User Forms", app "Forms Pro")
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰
I hopped in with a tiny cheer,
Planted a module, bright and near,
"User Forms" now springs to view,
Ready for forms, old and new,
A small patch—hoppity hooray!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: enabling automatic creation of a 'User Forms' module during app installation by activating the after_install hook.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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: 3

🤖 Fix all issues with AI agents
In @forms_pro/install.py:
- Around line 7-8: The before_install hook directly calls
create_user_forms_module without error handling; wrap the call in a try/except
inside before_install, catch broad exceptions from create_user_forms_module, log
the exception with context (e.g., using the project logger or frappe.log/print)
and allow installation to continue if this module creation is non-critical (do
not re-raise), or return a failure signal only if you decide it must stop
installation; refer to the before_install function and create_user_forms_module
by name when making the change.

In @forms_pro/patches/0_1_beta/create_user_forms_module_def.py:
- Around line 5-8: Fix the grammatical typo in the module docstring in
create_user_forms_module_def.py: replace the phrase "in the for the app `Forms
Pro`." with "for the app `Forms Pro`." so the docstring reads "Create a module
def `User Forms` for the app `Forms Pro`." and keep it as the top triple-quoted
string.
- Around line 4-9: The patch's execute() calls create_user_forms_module() with
no error handling, which can abort bench migrate on failure; wrap the call in a
try/except around execute() (or inside it), catch Exception as e, record the
full exception (e and traceback) using frappe.log_error or processLogger (e.g.,
frappe.log_error(e, "create_user_forms_module patch failed")), and ensure the
exception is handled so migrations continue (do not re-raise); reference the
execute() function and create_user_forms_module() when making this change.
🧹 Nitpick comments (1)
forms_pro/install.py (1)

11-18: Good idempotency pattern, consider adding logging.

The function correctly checks for existence before creating the module, making it safe to call multiple times (both from before_install and from the patch script).

📝 Optional: Add logging for better observability
 def create_user_forms_module():
     if frappe.db.exists("Module Def", "User Forms"):
         return
 
     module = frappe.new_doc("Module Def")
     module.module_name = "User Forms"
     module.app_name = "Forms Pro"
     module.insert(ignore_permissions=True)
+    frappe.logger().info("Created 'User Forms' module for Forms Pro")
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39edcf5 and 84b358b.

📒 Files selected for processing (4)
  • forms_pro/hooks.py
  • forms_pro/install.py
  • forms_pro/patches.txt
  • forms_pro/patches/0_1_beta/create_user_forms_module_def.py
🧰 Additional context used
🧬 Code graph analysis (2)
forms_pro/patches/0_1_beta/create_user_forms_module_def.py (1)
forms_pro/install.py (1)
  • create_user_forms_module (11-18)
forms_pro/hooks.py (1)
forms_pro/install.py (1)
  • before_install (7-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Server
🔇 Additional comments (4)
forms_pro/patches.txt (1)

4-4: LGTM! Patch entry is correctly formatted.

The patch identifier follows Frappe conventions and correctly references the new patch script.

forms_pro/hooks.py (1)

92-92: LGTM! Hook activation is correct.

The before_install hook is properly configured to invoke the module creation during installation.

forms_pro/patches/0_1_beta/create_user_forms_module_def.py (1)

1-9: LGTM! Good code reuse pattern.

The patch correctly delegates to the shared create_user_forms_module() function, ensuring consistent behavior between fresh installations and migrations. The idempotency check in that function prevents duplicate module creation.

forms_pro/install.py (1)

11-18: This concern is not applicable—the function is called from after_install, not before_install.

The before_install hook is commented out (hooks.py:92), and create_user_forms_module() is invoked from the active after_install hook (hooks.py:93, install.py:8). During after_install, the app's schema is already synced and Module Def (a core Frappe doctype) is guaranteed to be available. No timing issue exists here.

Likely an incorrect or invalid review comment.

Comment on lines 7 to 8
def before_install():
create_user_forms_module()
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling to prevent installation failures.

The before_install hook lacks error handling. If module creation fails (e.g., database connectivity issues, permission problems), it will break the entire installation process.

🛡️ Proposed fix with error handling and logging
 def before_install():
-    create_user_forms_module()
+    try:
+        create_user_forms_module()
+    except Exception as e:
+        frappe.log_error(
+            title="Failed to create User Forms module",
+            message=frappe.get_traceback()
+        )
+        # Re-raise to prevent installation if module creation is critical
+        raise

If module creation is non-critical and installation should proceed regardless, change to:

 def before_install():
-    create_user_forms_module()
+    try:
+        create_user_forms_module()
+    except Exception:
+        frappe.log_error(
+            title="Failed to create User Forms module",
+            message=frappe.get_traceback()
+        )
+        # Continue installation even if module creation fails
🤖 Prompt for AI Agents
In @forms_pro/install.py around lines 7 - 8, The before_install hook directly
calls create_user_forms_module without error handling; wrap the call in a
try/except inside before_install, catch broad exceptions from
create_user_forms_module, log the exception with context (e.g., using the
project logger or frappe.log/print) and allow installation to continue if this
module creation is non-critical (do not re-raise), or return a failure signal
only if you decide it must stop installation; refer to the before_install
function and create_user_forms_module by name when making the change.

Comment on lines +4 to +9
def execute():
"""
Create a module def `User Forms` in the for the app `Forms Pro`.
"""
create_user_forms_module()
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling for patch execution.

Similar to the before_install hook, the patch lacks error handling. If module creation fails during migration, it will break the bench migrate process for existing installations.

🛡️ Proposed fix with error handling
+import frappe
 from forms_pro.install import create_user_forms_module
 
 
 def execute():
     """
     Create a module def `User Forms` for the app `Forms Pro`.
 
     """
-    create_user_forms_module()
+    try:
+        create_user_forms_module()
+    except Exception as e:
+        frappe.log_error(
+            title="Patch failed: create_user_forms_module_def",
+            message=frappe.get_traceback()
+        )
+        # Re-raise to mark patch as failed
+        raise

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In @forms_pro/patches/0_1_beta/create_user_forms_module_def.py around lines 4 -
9, The patch's execute() calls create_user_forms_module() with no error
handling, which can abort bench migrate on failure; wrap the call in a
try/except around execute() (or inside it), catch Exception as e, record the
full exception (e and traceback) using frappe.log_error or processLogger (e.g.,
frappe.log_error(e, "create_user_forms_module patch failed")), and ensure the
exception is handled so migrations continue (do not re-raise); reference the
execute() function and create_user_forms_module() when making this change.

Comment on lines +5 to +8
"""
Create a module def `User Forms` in the for the app `Forms Pro`.
"""
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammatical error in docstring.

Line 6 contains a typo: "in the for the app" should be "for the app".

📝 Proposed fix
 def execute():
     """
-    Create a module def `User Forms` in the for the app `Forms Pro`.
+    Create a module def `User Forms` for the app `Forms Pro`.
 
     """
     create_user_forms_module()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Create a module def `User Forms` in the for the app `Forms Pro`.
"""
def execute():
"""
Create a module def `User Forms` for the app `Forms Pro`.
"""
create_user_forms_module()
🤖 Prompt for AI Agents
In @forms_pro/patches/0_1_beta/create_user_forms_module_def.py around lines 5 -
8, Fix the grammatical typo in the module docstring in
create_user_forms_module_def.py: replace the phrase "in the for the app `Forms
Pro`." with "for the app `Forms Pro`." so the docstring reads "Create a module
def `User Forms` for the app `Forms Pro`." and keep it as the top triple-quoted
string.

Copy link

@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: 2

🤖 Fix all issues with AI agents
In @forms_pro/utils/test_form_generator.py:
- Around line 306-307: Remove the @unittest.skip decorator from the skipped test
and update the test setup so it does not create core DocTypes under module="User
Forms" (use a test-specific module name like "Test - User Forms" or a randomized
module), and ensure both this test and test_status_field_is_added_core_doctype
create and teardown their DocTypes cleanly (delete created DocTypes in tearDown
or use context-managed creation) so they no longer conflict with core module
validation; run both tests together to confirm they pass.
- Around line 264-265: The tests are skipped because the "User Forms" module
isn't created in the test environment; update the before_tests() function in
install.py to call create_user_forms_module() before creating roles/users (i.e.,
ensure before_tests() invokes create_user_forms_module(), then
give_admin_forms_pro_role(), then create_test_user()) so DocType creations using
module="User Forms" succeed during tests.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7117ef and ad2c8e9.

📒 Files selected for processing (1)
  • forms_pro/utils/test_form_generator.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Server
🔇 Additional comments (1)
forms_pro/utils/test_form_generator.py (1)

4-4: LGTM: Import is necessary for skip decorators.

The unittest import is required for the @unittest.skip decorators used in the tests below.

Comment on lines +264 to +265
# TODO: Fix this test
@unittest.skip("Skipping this test as it is not working as expected")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's view the test file around lines 264-265
head -n 275 forms_pro/utils/test_form_generator.py | tail -n 20

Repository: BuildWithHussain/forms_pro

Length of output: 1214


🏁 Script executed:

# Check the entire setUp methods to understand test initialization
rg -n 'def setUp|def setUpClass|def setUpModule' forms_pro/utils/test_form_generator.py -A 20

Repository: BuildWithHussain/forms_pro

Length of output: 972


🏁 Script executed:

# Look for User Forms module creation in test setup
rg -n 'User Forms' forms_pro/utils/test_form_generator.py -B 3 -A 3

Repository: BuildWithHussain/forms_pro

Length of output: 1427


🏁 Script executed:

# Check install.py for module creation logic
cat forms_pro/install.py

Repository: BuildWithHussain/forms_pro

Length of output: 1123


🏁 Script executed:

# Look for other test setup or fixtures that might create modules
fd -t f 'conftest\|fixtures\|setup' forms_pro/

Repository: BuildWithHussain/forms_pro

Length of output: 52


Add create_user_forms_module() call to before_tests() to fix test failures.

The skipped tests fail because the "User Forms" module is not created in the test environment. The before_tests() hook in install.py only calls give_admin_forms_pro_role() and create_test_user() but does not call create_user_forms_module(). When the test tries to create a DocType with module = "User Forms", the module doesn't exist, causing the test to fail.

Update before_tests() to include:

def before_tests():
    create_user_forms_module()
    give_admin_forms_pro_role()
    create_test_user()

This ensures the module exists before tests run, allowing these tests to pass without being skipped.

🤖 Prompt for AI Agents
In @forms_pro/utils/test_form_generator.py around lines 264 - 265, The tests are
skipped because the "User Forms" module isn't created in the test environment;
update the before_tests() function in install.py to call
create_user_forms_module() before creating roles/users (i.e., ensure
before_tests() invokes create_user_forms_module(), then
give_admin_forms_pro_role(), then create_test_user()) so DocType creations using
module="User Forms" succeed during tests.

Comment on lines +306 to +307
# TODO: Fix this test
@unittest.skip("Skipping this test as it is not working as expected")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Same concern as the previous skipped test.

This test is skipped for the same reason as test_status_field_is_added_core_doctype above. Both tests create core DocTypes with module = "User Forms" and likely fail for the same reason.

Please address both skipped tests together as part of a single remediation effort.

🤖 Prompt for AI Agents
In @forms_pro/utils/test_form_generator.py around lines 306 - 307, Remove the
@unittest.skip decorator from the skipped test and update the test setup so it
does not create core DocTypes under module="User Forms" (use a test-specific
module name like "Test - User Forms" or a randomized module), and ensure both
this test and test_status_field_is_added_core_doctype create and teardown their
DocTypes cleanly (delete created DocTypes in tearDown or use context-managed
creation) so they no longer conflict with core module validation; run both tests
together to confirm they pass.

@harshtandiya harshtandiya merged commit c8ab3e4 into develop Jan 8, 2026
4 checks passed
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.

2 participants