google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Cloud Run Service Level Scaling returns 409

Open hfurkanvural opened this issue 5 months ago • 1 comments

Determine this is the right repository

  • [x] I determined this is the correct repository in which to report this bug.

Summary of the issue

Context I wanna manage my cloud run function's service level scaling from python client. however i get 409 error even though it should not trigger a new version according to the behaviour on UI.

Here is the example code:

        # Get the current service
        service = client.get_service(name=service_name)
        
        service.scaling.min_instance_count = min_instances

        update_mask = field_mask_pb2.FieldMask(
            paths=["scaling.minInstanceCount"]
        )

        update_request = run_v2.UpdateServiceRequest(
            service=service,
            update_mask=update_mask,
            allow_missing=False
        )
        
        # Update the service
        operation = client.update_service(request=update_request)
        

Expected Behavior: The Scaling value is updated without an error message

Image

Actual Behavior: Update operation returns the following error message: 409 Revision named '' with different configuration already exists.

API client name and version

google-cloud-run 0.10.9

Reproduction steps: code

file: main.py

        # Get the current service
        service = client.get_service(name=service_name)
        
        service.scaling.min_instance_count = min_instances

        update_mask = field_mask_pb2.FieldMask(
            paths=["scaling.minInstanceCount"] ## also tried scaling.min_instance_count
        )

        update_request = run_v2.UpdateServiceRequest(
            service=service,
            update_mask=update_mask,
            allow_missing=False
        )
        
        # Update the service
        operation = client.update_service(request=update_request)

Reproduction steps: supporting files

Reproduction steps: actual results

409 Revision named '' with different configuration already exists.

Reproduction steps: expected results

HTTP 200

OS & version + platform

MacOS Sequoia

Python environment

3.11.9

Python dependencies

google-api-core 2.25.1 google-auth 2.40.3 google-cloud-run 0.10.9 googleapis-common-protos 1.70.0

Additional context

No response

hfurkanvural avatar Aug 20 '25 20:08 hfurkanvural

Hi @hfurkanvural,

This should solve your issue: patch the revision template and use the snake_case path in the update mask.

name = f"projects/{PROJECT_ID}/locations/{REGION}/services/{SERVICE_NAME}"
client = ServicesClient()

patch = Service(
    name=name,
    template=RevisionTemplate(
        scaling=RevisionScaling(
            min_instance_count=target_min,
        )
    ),
)

update_mask = FieldMask(paths=["template.scaling.min_instance_count"])

operation = client.update_service(request=UpdateServiceRequest(service=patch, update_mask=update_mask))

operation.result()  # Wait for the operation to complete

hamza-56 avatar Aug 25 '25 22:08 hamza-56