#22118·meshery

[Server] Updating an unknown local environment creates it

Author: maverickaayushCreated Sep 27, 2026Updated Sep 28, 2026

Description

PUT /api/environments/{id} creates a new local environment when the requested ID does not exist. An update endpoint therefore acts as an undocumented upsert and reports success instead of not found.

Current Behavior

Calling DefaultLocalProvider.UpdateEnvironment with a valid but unknown UUID returns success and inserts one row under that UUID.

Expected Behavior

Updating an unknown environment should not create it; the API should return the documented not-found response.

Steps to Reproduce

  1. Start with an empty migrated environment table.
  2. Call UpdateEnvironment using a newly generated UUID and a valid payload.
  3. Observe a nil error.
  4. Count rows and observe that one environment was inserted.

Evidence

$ go test ./server/models -run '^TestReproLocalEnvironmentUpdateUnknownIDDoesNotInsert$' -count=1
update of a missing environment returned success
update of missing id inserted 1 environment row(s)
FAIL

Root Cause

DefaultLocalProvider.UpdateEnvironment passes a newly constructed object directly to EnvironmentPersister.UpdateEnvironmentByID, which uses GORM Save. Save inserts when the primary key is absent instead of enforcing update-only semantics.

Affected Components

  • Meshery Server
  • Local provider
  • Environment REST API/persistence

Validation

Executed on master commit 5b75615243e92b088b4ebf6e7bff82d6f60e5462:

go test ./server/models -run '^TestReproLocalEnvironmentUpdateUnknownIDDoesNotInsert$' -count=1

Result: deterministic failure; the update inserts a new row and returns success.

Acceptance Criteria

  • An update affects only an existing environment.
  • An unknown ID returns a not-found error/status and inserts no row.
  • A regression test asserts both the response and row count.

References