Skip to content

Fix/auto labeling optional fields#2451

Open
tossyi wants to merge 3 commits intodoccano:masterfrom
tossyi:fix/auto-labeling-optional-fields
Open

Fix/auto labeling optional fields#2451
tossyi wants to merge 3 commits intodoccano:masterfrom
tossyi:fix/auto-labeling-optional-fields

Conversation

@tossyi
Copy link

@tossyi tossyi commented Nov 24, 2025

Summary

  • Add monkey-patch to CustomRESTRequestModel with default values for optional fields
  • Convert UI format (array of objects) to backend format (dict) in serializers and views
  • Handle empty strings from ObjectField by converting to empty dicts
  • Auto-populate request body with {\"text\": example} when empty
  • Fix template.ts to detect object type in anyOf schemas
  • Fix ConfigCreationForm.vue watch handler to allow optional fields without testing requirement

What This Fixes

Fixes GitHub Issue #2395 - Users can now configure REST API templates without requiring params, headers, or body fields to be populated.
These fields are now properly treated as optional.

Changes Made

Backend

  • backend/auto_labeling/__init__.py - New file with monkey-patch for default values
  • backend/auto_labeling/serializers.py - Convert empty strings to empty dicts
  • backend/auto_labeling/views.py - Handle optional field defaults and auto-populate body

Frontend

  • frontend/domain/models/autoLabeling/template.ts - Detect object types in anyOf schemas
  • frontend/components/configAutoLabeling/ConfigCreationForm.vue - Allow optional fields without test requirement

Testing

All changes have been tested and verified to work with BERT API integration.

tossyi and others added 3 commits November 24, 2025 13:26
…late

- Add monkey-patch in __init__.py to provide default values for optional fields
  in CustomRESTRequestModel, making them truly optional (not required)
- Convert UI format (array of objects) to backend format (dict) in serializers.py
  and views.py create_model() method
- Handle empty strings from ObjectField by converting to empty dicts
- Auto-populate request body with {"text": example} when empty in send_request()
- Fix template.ts to detect object type in anyOf schemas and render as objectField
- Fix ConfigCreationForm.vue watch handler to allow optional fields without
  requiring test status reset

This fixes GitHub Issue doccano#2395 allowing users to configure REST API templates
without requiring params, headers, or body fields to be populated.
When frontend ObjectField components send empty values (empty strings or
empty arrays), convert them to empty dictionaries before Pydantic validation.

This fixes the issue where params, headers, body fields would fail validation
with "Input should be a valid dictionary" errors when users don't fill in
optional object fields.

Also improves validation by checking if fields contain empty values even if
they already exist in attrs_dict.
Fixed an issue where Custom REST Request auto-labeling was sending template
variable {{text}} instead of the actual text content to the API, resulting in
422 errors and incorrect labeling.

Changes:
- Set actual text in model.body before calling pipeline (execution.py)
- Add Content-Type: application/json header automatically (execution.py, views.py)
- Provide default values for empty params, headers, and body fields (execution.py)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

1 participant