Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dbless): nest duplicate entity primary key errors for children #12797

Merged
merged 1 commit into from
Apr 23, 2024

Commits on Apr 10, 2024

  1. fix(dbless): nest duplicate entity primary key errors for children

    This makes a change to the shape/structure of dbless errors. Before this
    change, an upstream with duplicate targets would yield a response like
    this:
    
    ```
    {
      "code": 14,
      "fields": {
        "targets": [
          null,
          "uniqueness violation: 'targets' entity with primary key set to '48322e4a-b3b0-591b-8ed6-fd95a6d75019' already declared"
        ]
      },
      "message": "declarative config is invalid: {targets={[2]=\"uniqueness violation: 'targets' entity with primary key set to '48322e4a-b3b0-591b-8ed6-fd95a6d75019' already declared\"}}",
      "name": "invalid declarative configuration"
    }
    ```
    
    After this change, the errors are nested under the parent upstream:
    
    ```
    {
      "code": 14,
      "fields": {
        "upstreams": [
          null,
          {
            "targets": [
              null,
              "uniqueness violation: 'targets' entity with primary key set to '48322e4a-b3b0-591b-8ed6-fd95a6d75019' already declared"
            ]
          }
        ]
      },
      "message": "declarative config is invalid: {upstreams={[2]={targets={[2]=\"uniqueness violation: 'targets' entity with primary key set to '48322e4a-b3b0-591b-8ed6-fd95a6d75019' already declared\"}}}}",
      "name": "invalid declarative configuration"
    }
    ```
    
    As a result, the error can now be properly mapped to the input target,
    so `POST /config?flatten_errors=1` returns a helpful result:
    
    ```
    {
      "code": 14,
      "fields": {},
      "flattened_errors": [
        {
          "entity": {
            "id": "48322e4a-b3b0-591b-8ed6-fd95a6d75019",
            "tags": [
              "target-2"
            ],
            "target": "10.244.0.12:80",
            "upstream": {
              "id": "f9792964-6797-482c-bfdf-08220a4f6839"
            },
            "weight": 1
          },
          "entity_id": "48322e4a-b3b0-591b-8ed6-fd95a6d75019",
          "entity_tags": [
            "target-2"
          ],
          "entity_type": "target",
          "errors": [
            {
              "message": "uniqueness violation: 'targets' entity with primary key set to '48322e4a-b3b0-591b-8ed6-fd95a6d75019' already declared",
              "type": "entity"
            }
          ]
        }
      ],
      "message": "declarative config is invalid: {}",
      "name": "invalid declarative configuration"
    }
    ```
    flrgh committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    518df6d View commit details
    Browse the repository at this point in the history