Skip to content

🔧(backend) settings CONVERSION_UPLOAD_ENABLED to control usage of docspec#2151

Merged
lunika merged 3 commits into
mainfrom
docspec-feature-flag
Mar 30, 2026
Merged

🔧(backend) settings CONVERSION_UPLOAD_ENABLED to control usage of docspec#2151
lunika merged 3 commits into
mainfrom
docspec-feature-flag

Conversation

@lunika
Copy link
Copy Markdown
Member

@lunika lunika commented Mar 30, 2026

Purpose

We want to control the conversion of document at upload time. We want to
disable this feature using a settings. The new settings
CONVERSION_UPLOAD_ENABLED should be used to enable or not the conversion
at upload feature. If disabled and a file is uploaded, the reponse will
return a 400

Proposal

  • 🔧(backend) settings CONVERSION_UPLOAD_ENABLED to control usage of docspec
  • 🔧(backend) expose CONVERSION_UPLOAD_ENABLED in config endpoint

@lunika lunika requested a review from jmaupetit March 30, 2026 09:43
@lunika lunika self-assigned this Mar 30, 2026
@lunika lunika added the enhancement improve an existing feature label Mar 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

A new boolean feature flag CONVERSION_UPLOAD_ENABLED (default False, env-configurable) was added. Backend: the setting is exposed via the config endpoint and DocumentViewSet.perform_create now rejects requests that include an uploaded file when the flag is False. Tests were updated to enable the flag where needed and a new negative test covers the disabled path. Frontend: runtime test config and e2e tests updated; ConfigResponse gains an optional CONVERSION_UPLOAD_ENABLED field; useImport returns isEnabled and DocsGrid gates upload UI accordingly. CHANGELOG and development env vars updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a CONVERSION_UPLOAD_ENABLED backend setting to control docspec conversion usage.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the purpose and proposal for the CONVERSION_UPLOAD_ENABLED setting.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docspec-feature-flag

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
Copy Markdown

@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

🧹 Nitpick comments (1)
src/backend/core/tests/documents/test_api_documents_create_with_file.py (1)

43-53: Consider centralizing repeated flag setup in a fixture.

settings.CONVERSION_UPLOAD_ENABLED = True is repeated across many tests. A local fixture (or autouse fixture scoped to this module) would reduce duplication and keep intent clearer.

♻️ Example refactor
+@pytest.fixture
+def conversion_upload_enabled(settings):
+    settings.CONVERSION_UPLOAD_ENABLED = True
+    return settings
+
 `@patch`("core.services.converter_services.Converter.convert")
-def test_api_documents_create_with_docx_file_success(mock_convert, settings):
+def test_api_documents_create_with_docx_file_success(mock_convert, conversion_upload_enabled):
@@
-    settings.CONVERSION_UPLOAD_ENABLED = True

Also applies to: 121-130, 163-172, 197-206, 225-234, 257-266, 314-323, 341-352, 384-393, 421-422, 448-449

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backend/core/tests/documents/test_api_documents_create_with_file.py`
around lines 43 - 53, Multiple tests (e.g.,
test_api_documents_create_with_docx_file_success and others listed) repeatedly
set settings.CONVERSION_UPLOAD_ENABLED = True; add a single pytest fixture
(e.g., enable_conversion_upload) in this test module (or as an autouse fixture
scoped to the module) that sets settings.CONVERSION_UPLOAD_ENABLED = True before
yielding and restores the original value afterward, then remove the repeated
assignments from the individual tests so they rely on the fixture.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/backend/impress/settings.py`:
- Around line 869-871: The environment variable name passed to
values.BooleanValue for the CONVERSION_UPLOAD_ENABLED setting is incorrect;
update the environ_name argument in the CONVERSION_UPLOAD_ENABLED declaration
(where values.BooleanValue is called) from "CONVERSION_ENABLED" to
"CONVERSION_UPLOAD_ENABLED" so the environment variable matches the
public-facing setting name used across the codebase and CHANGELOG (leave
environ_prefix=None as-is).

---

Nitpick comments:
In `@src/backend/core/tests/documents/test_api_documents_create_with_file.py`:
- Around line 43-53: Multiple tests (e.g.,
test_api_documents_create_with_docx_file_success and others listed) repeatedly
set settings.CONVERSION_UPLOAD_ENABLED = True; add a single pytest fixture
(e.g., enable_conversion_upload) in this test module (or as an autouse fixture
scoped to the module) that sets settings.CONVERSION_UPLOAD_ENABLED = True before
yielding and restores the original value afterward, then remove the repeated
assignments from the individual tests so they rely on the fixture.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 908db155-636c-4ffc-ad04-3c30eef1cf13

📥 Commits

Reviewing files that changed from the base of the PR and between 79e909c and 126b45d.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • src/backend/core/api/viewsets.py
  • src/backend/core/tests/documents/test_api_documents_create_with_file.py
  • src/backend/core/tests/external_api/test_external_api_documents.py
  • src/backend/core/tests/test_api_config.py
  • src/backend/impress/settings.py

Comment thread src/backend/impress/settings.py
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 30, 2026

Size Change: +1 B (0%)

Total Size: 4.25 MB

📦 View Changed
Filename Size Change
apps/impress/out/_next/static/342c3141/_buildManifest.js 0 B -621 B (removed) 🏆
apps/impress/out/_next/static/07331dc1/_buildManifest.js 622 B +622 B (new file) 🆕

compressed-size-action

@lunika
Copy link
Copy Markdown
Member Author

lunika commented Mar 30, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lunika lunika force-pushed the docspec-feature-flag branch from 599e2cd to 788d594 Compare March 30, 2026 12:14
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/backend/core/tests/documents/test_api_documents_create_with_file.py`:
- Around line 86-118: In test_api_documents_create_with_docx_file_disabled, add
an assertion that no Document row is persisted when uploads are disabled: record
the initial Document.objects.count() (or use Document.objects.filter(...) for a
unique attribute) before the POST and assert the count is unchanged after the
response (or that no Document matching the uploaded file name exists); place
this check after the response assertions and before
mock_convert.assert_not_called() to ensure no partial write occurred. Use the
Document model (Document) and the test function name
test_api_documents_create_with_docx_file_disabled to locate where to add the
assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ef983b00-58d8-468f-bb6f-06eb3444c996

📥 Commits

Reviewing files that changed from the base of the PR and between 599e2cd and 788d594.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • env.d/development/common
  • src/backend/core/api/viewsets.py
  • src/backend/core/tests/documents/test_api_documents_create_with_file.py
  • src/backend/core/tests/external_api/test_external_api_documents.py
  • src/backend/core/tests/test_api_config.py
  • src/backend/impress/settings.py
  • src/frontend/apps/e2e/__tests__/app-impress/doc-import.spec.ts
  • src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts
  • src/frontend/apps/impress/src/core/config/api/useConfig.tsx
  • src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx
  • src/frontend/apps/impress/src/features/docs/docs-grid/hooks/useImport.tsx

Copy link
Copy Markdown

@jmaupetit jmaupetit left a comment

Choose a reason for hiding this comment

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

I only have minor suggestions. Take it or leave it.

Comment thread src/backend/core/api/viewsets.py Outdated
Comment thread src/backend/core/tests/documents/test_api_documents_create_with_file.py Outdated
lunika and others added 3 commits March 30, 2026 15:37
We want to control the conversion of document at upload time. We want to
disable this feature using a settings. The new settings
CONVERSION_UPLOAD_ENABLED should be used to enable or not the conversion
at upload feature. If disabled and a file is uploaded, the reponse will
return a 400
The frontend application needs to know the value of the settings
CONVERSION_UPLOAD_ENABLED to allow the file upload or not.
We want to be able to enable/disable the document
import feature for testing and gradual rollout
purposes. This commit adds a feature flag for
document import and updates the relevant components
and tests to respect this flag.
@lunika lunika force-pushed the docspec-feature-flag branch from 788d594 to f166e75 Compare March 30, 2026 13:37
Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
src/backend/core/tests/documents/test_api_documents_create_with_file.py (1)

86-114: ⚠️ Potential issue | 🟡 Minor

Add assertion to verify no document was persisted.

The test should verify that no Document is created when upload is rejected. This guards against partial writes before validation and ensures data integrity.

Suggested fix
     assert response.status_code == 400
     assert response.json() == {"file": ["file upload is not allowed"]}
+    assert not Document.objects.exists()
 
     # Verify the converter was not called
     mock_convert.assert_not_called()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backend/core/tests/documents/test_api_documents_create_with_file.py`
around lines 86 - 114, The test
test_api_documents_create_with_docx_file_disabled should also assert that no
Document was persisted when upload is rejected; after the response and before
mock_convert.assert_not_called(), query the Document model (e.g.,
Document.objects.count() == 0 or assert not Document.objects.exists()) to ensure
no partial write occurred; update the test to import the Document model if
necessary and add a single assertion verifying zero persisted Document
instances.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/frontend/apps/impress/src/features/docs/docs-grid/hooks/useImport.tsx`:
- Around line 115-121: Replace the fallback operator used when deriving the
exported isEnabled flag to make the intent explicit: change the expression that
returns isEnabled (currently using config?.CONVERSION_UPLOAD_ENABLED || false)
to use nullish coalescing so it only falls back for null/undefined (i.e., use
config?.CONVERSION_UPLOAD_ENABLED ?? false); update the return object where
getRootProps, getInputProps, open, and isEnabled are returned.

---

Duplicate comments:
In `@src/backend/core/tests/documents/test_api_documents_create_with_file.py`:
- Around line 86-114: The test test_api_documents_create_with_docx_file_disabled
should also assert that no Document was persisted when upload is rejected; after
the response and before mock_convert.assert_not_called(), query the Document
model (e.g., Document.objects.count() == 0 or assert not
Document.objects.exists()) to ensure no partial write occurred; update the test
to import the Document model if necessary and add a single assertion verifying
zero persisted Document instances.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 977738ff-8b0d-4465-bd2b-cf1a48b7bc26

📥 Commits

Reviewing files that changed from the base of the PR and between 788d594 and f166e75.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • env.d/development/common
  • src/backend/core/api/viewsets.py
  • src/backend/core/tests/documents/test_api_documents_create_with_file.py
  • src/backend/core/tests/external_api/test_external_api_documents.py
  • src/backend/core/tests/test_api_config.py
  • src/backend/impress/settings.py
  • src/frontend/apps/e2e/__tests__/app-impress/doc-import.spec.ts
  • src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts
  • src/frontend/apps/impress/src/core/config/api/useConfig.tsx
  • src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx
  • src/frontend/apps/impress/src/features/docs/docs-grid/hooks/useImport.tsx

Comment on lines +115 to +121
return {
getRootProps,
getInputProps,
open,
isEnabled: config?.CONVERSION_UPLOAD_ENABLED || false,
isPending,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

LGTM! Feature flag properly exposed from hook.

The hook correctly derives isEnabled from the config and returns it for consumers to gate UI behavior.

💡 Optional: Consider nullish coalescing for clearer intent
-    isEnabled: config?.CONVERSION_UPLOAD_ENABLED || false,
+    isEnabled: config?.CONVERSION_UPLOAD_ENABLED ?? false,

Using ?? instead of || makes it explicit that you're only providing a fallback for null/undefined, not for other falsy values. Since this is a boolean, both operators behave identically, but ?? better communicates the intent.

📝 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
return {
getRootProps,
getInputProps,
open,
isEnabled: config?.CONVERSION_UPLOAD_ENABLED || false,
isPending,
};
return {
getRootProps,
getInputProps,
open,
isEnabled: config?.CONVERSION_UPLOAD_ENABLED ?? false,
isPending,
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/frontend/apps/impress/src/features/docs/docs-grid/hooks/useImport.tsx`
around lines 115 - 121, Replace the fallback operator used when deriving the
exported isEnabled flag to make the intent explicit: change the expression that
returns isEnabled (currently using config?.CONVERSION_UPLOAD_ENABLED || false)
to use nullish coalescing so it only falls back for null/undefined (i.e., use
config?.CONVERSION_UPLOAD_ENABLED ?? false); update the return object where
getRootProps, getInputProps, open, and isEnabled are returned.

@lunika lunika merged commit f166e75 into main Mar 30, 2026
34 of 36 checks passed
@lunika lunika deleted the docspec-feature-flag branch March 30, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants