Skip to content

fix: prevent adding cameras with invalid model names (#1162)#1445

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/apply-pr-1165-change
Open

fix: prevent adding cameras with invalid model names (#1162)#1445
Copilot wants to merge 2 commits into
mainfrom
copilot/apply-pr-1165-change

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

📝 Description

Applies the changes from #1165 to main.

When adding a camera, the system allowed specifying a model name that does not exist in the configured model list (model-config). The camera would still be created successfully even though the model was invalid.

This could result in a confusing state where:

  • The camera appears in the system
  • No video feed is processed
  • No object tracking appears on the GUI

This change introduces validation during camera creation to ensure that the provided model name exists in model-config. If the model is not found, the request is rejected with a validation error.

Fixes #1162


🔍 Behavior Before / After

Before

  • Cameras could be created with invalid model names that were not present in model-config.
  • The camera would appear in the system but no feed or tracking would be available on the GUI.

After

  • The system validates the model name during camera creation.
  • If the specified model does not exist in model-config, the request is rejected with an appropriate 400 validation error.

✨ Type of Change

  • 🐞 Bug fix – Non-breaking change which fixes an issue

✅ Changes

  • manager/src/manager/forms.py: Added clean_camerachain validation method to CamCreateForm that reads model-config and validates the provided model name via parse_model_chain.
  • manager/src/manager/views.py: Added form_invalid override to CamCreateView to return HTTP 400 on validation failure.
  • tests/sscape_tests/cam/test_cam_create.py: Updated expected status code from 200 to 400 for invalid camera creation submissions.

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

This PR fixes an invalid camera configuration path in the manager service by validating the submitted camera model chain against the configured model_config.json during camera creation, rejecting invalid configurations early to avoid “camera exists but no tracking” states.

Changes:

  • Add CamCreateForm.clean_camerachain() validation that loads model-config and validates the chain via parse_model_chain.
  • Return HTTP 400 from CamCreateView when the submitted form is invalid.
  • Update the camera-create test to expect 400 on invalid submissions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
manager/src/manager/forms.py Adds clean_camerachain validation by loading model config and validating the chain.
manager/src/manager/views.py Overrides form_invalid to respond with HTTP 400 on validation errors.
tests/sscape_tests/cam/test_cam_create.py Adjusts expected status code for invalid camera creation POSTs.

Comment on lines +195 to +203
model_config_path = Path(os.environ.get('MODEL_CONFIGS_FOLDER', '/models/model_configs')) / model_config_filename
if not model_config_path.is_file():
raise ValidationError(f"Model config file not found at {model_config_path}")

try:
with open(model_config_path, 'r') as f:
model_config = json.load(f)
except (json.JSONDecodeError, IOError) as e:
raise ValidationError(f"Error reading model config: {str(e)}")
Comment on lines 18 to +20
def test_cam_create_page(self):
response = self.client.post(reverse('cam_create'), data = {'sensor_id': '100', 'name': 'test_camera', 'scene': 'test_scene'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 400)
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines 18 to +20
def test_cam_create_page(self):
response = self.client.post(reverse('cam_create'), data = {'sensor_id': '100', 'name': 'test_camera', 'scene': 'test_scene'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 400)
Comment on lines +194 to +203
model_config_filename = getattr(self.instance, 'modelconfig', None) or 'model_config.json'
model_config_path = Path(os.environ.get('MODEL_CONFIGS_FOLDER', '/models/model_configs')) / model_config_filename
if not model_config_path.is_file():
raise ValidationError(f"Model config file not found at {model_config_path}")

try:
with open(model_config_path, 'r') as f:
model_config = json.load(f)
except (json.JSONDecodeError, IOError) as e:
raise ValidationError(f"Error reading model config: {str(e)}")
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.

[Bug - NOK] Camera creation does not validate model name against model-config

3 participants