Skip to content

fix: ProcessingService create fails with TypeError on project field#1210

Merged
mihow merged 3 commits intomainfrom
fix/processing-service-create-1209
Apr 4, 2026
Merged

fix: ProcessingService create fails with TypeError on project field#1210
mihow merged 3 commits intomainfrom
fix/processing-service-create-1209

Conversation

@mihow
Copy link
Copy Markdown
Collaborator

@mihow mihow commented Apr 4, 2026

Summary

  • Remove stale write-only project field from ProcessingServiceSerializer that caused TypeError: ProcessingService() got unexpected keyword arguments: 'project' when creating a processing service via the API

Root cause

PR #1094 moved project assignment from the serializer's create() to perform_create() (which uses get_active_project() from the query string), but left the write-only project PrimaryKeyRelatedField on the serializer. DRF's default create() then passed it to ProcessingService.objects.create(project=<Project>), which fails because ProcessingService has a M2M projects field, not a FK project.

Pattern

This now matches the established pattern for M2M project models (TaxaList, Pipeline): no writable project field on the serializer, project assignment handled in perform_create via get_active_project() from the project_id query parameter.

Test plan

  • Create a new processing service via the UI dialog — succeeds without 500
  • Service is assigned to the active project
  • Creating sites and devices still works (they use the same convertToServerFieldValues util, which is unchanged)

Closes #1209

🤖 Generated with Claude Code

The serializer had a write-only `project` PrimaryKeyRelatedField that was
passed through to ProcessingService.objects.create(), but ProcessingService
uses a M2M `projects` field, not a FK. This caused a TypeError on create.

The field was left behind when #1094 moved project assignment to
perform_create (which uses get_active_project from the query string).
Remove the field entirely to match the TaxaList pattern: no writable
project field on the serializer, M2M handled in perform_create.

Also rename `project` to `project_id` in the frontend's generic
convertToServerFieldValues to follow the codebase naming convention
(ID values use _id suffix).

Closes #1209

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 4, 2026 06:14
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 4, 2026

Deploy Preview for antenna-ssec ready!

Name Link
🔨 Latest commit bad0c65
🔍 Latest deploy log https://app.netlify.com/projects/antenna-ssec/deploys/69d0af28b2457d0008ed3d9e
😎 Deploy Preview https://deploy-preview-1210--antenna-ssec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 4, 2026

Deploy Preview for antenna-preview ready!

Name Link
🔨 Latest commit bad0c65
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/69d0af280446c80008e01fb9
😎 Deploy Preview https://deploy-preview-1210--antenna-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 76 (🟢 up 11 from production)
Accessibility: 97 (🟢 up 8 from production)
Best Practices: 92 (🔴 down 8 from production)
SEO: 100 (🟢 up 8 from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

Fixes a ProcessingService creation error by removing a write-only project field from the serializer that was being rejected by the model's create() method, and updates the client-side field mapping to send project_id instead of project.

Changes

Cohort / File(s) Summary
Backend Serializer
ami/ml/serializers.py
Removed write-only project field and corresponding Meta.fields entry from ProcessingServiceSerializer; eliminated unused Project import. Resolves model creation TypeError from passing invalid project argument.
Frontend Field Mapping
ui/src/data-services/hooks/entities/utils.ts
Updated convertToServerFieldValues to map projectId to project_id instead of project, aligning client payload with server expectations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🐰 A field caused trouble, wouldn't behave,
So we plucked it out and gave it a grave,
Now project_id flows, clean and bright,
Services spring forth—what a delight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary fix: removing a stale project field that causes a TypeError when creating ProcessingService instances.
Linked Issues check ✅ Passed The PR addresses all requirements from issue #1209: fixes the TypeError by removing the invalid project field from the serializer, ensures correct project assignment via get_active_project(), and restores the ability to create processing services.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the processing service creation error: removing the problematic serializer field, updating the frontend field name mapping, and aligning with the M2M project pattern used by other models.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description comprehensively addresses the root cause, solution, pattern alignment, test plan, and issue closure.

✏️ 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 fix/processing-service-create-1209

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.

DRF ignores unknown fields in request body, so no need to strip
`project` before passing to the serializer.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a backend 500 when creating ML processing services by removing an invalid writable project field from the DRF serializer and adding a legacy-body-field cleanup in the view, while attempting to align frontend payload naming to project_id.

Changes:

  • Backend: remove stale write-only project field from ProcessingServiceSerializer and drop it from Meta.fields.
  • Backend: strip legacy "project" from POST bodies in ProcessingServiceViewSet.create() to avoid TypeError for old clients.
  • Frontend: rename entity payload field from project to project_id in convertToServerFieldValues.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ui/src/data-services/hooks/entities/utils.ts Changes outgoing entity payload from project to project_id.
ami/ml/views.py Drops legacy project key from create payload before serializer validation.
ami/ml/serializers.py Removes invalid writable project field from the processing service serializer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Site, Device, and StorageSource serializers still expect `project`
(not `project_id`) as a writable PrimaryKeyRelatedField in the request
body. The ProcessingService fix is backend-only — the serializer no
longer declares a `project` field, so DRF silently ignores it.

Co-Authored-By: Claude <noreply@anthropic.com>
@mihow mihow merged commit 3f73ecc into main Apr 4, 2026
7 checks passed
@mihow mihow deleted the fix/processing-service-create-1209 branch April 4, 2026 06:35
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.

Cannot create a new service

2 participants