Skip to content

SQL Error "1 ambiguous column name" when attaching a control/implementation/risk to a policy #271

@knuffelhaeschen13

Description

@knuffelhaeschen13

Steps to re-create:

  1. create a policy. save
  2. edit the policy
  3. attach a control:
Illuminate\Database\QueryException
vendor/laravel/framework/src/Illuminate/Database/Connection.php:838

SQLSTATE[HY000]: General error: 1 ambiguous column name: id (Connection: sqlite, Database: /var/www/html/database/opengrc.sqlite, SQL: select distinct "id", "code", "title" from "controls" left join "control_policy" on "controls"."id" = "control_policy"."control_id" where not exists (select * from "policies" inner join "control_policy" on "policies"."id" = "control_policy"."policy_id" where "controls"."id" = "control_policy"."control_id" and "policies"."id" = 1 and "policies"."deleted_at" is null) and "controls"."deleted_at" is null limit 50) 
  1. attach a risk
Illuminate\Database\QueryException
vendor/laravel/framework/src/Illuminate/Database/Connection.php:838

SQLSTATE[HY000]: General error: 1 ambiguous column name: id (Connection: sqlite, Database: /var/www/html/database/opengrc.sqlite, SQL: select distinct "id", "name" from "risks" left join "policy_risk" on "risks"."id" = "policy_risk"."risk_id" where not exists (select * from "policies" inner join "policy_risk" on "policies"."id" = "policy_risk"."policy_id" where "risks"."id" = "policy_risk"."risk_id" and "policies"."id" = 1 and "policies"."deleted_at" is null) limit 50) 
  1. attach an implementation
Illuminate\Database\QueryException
vendor/laravel/framework/src/Illuminate/Database/Connection.php:838

SQLSTATE[HY000]: General error: 1 ambiguous column name: id (Connection: sqlite, Database: /var/www/html/database/opengrc.sqlite, SQL: select distinct "id", "title" from "implementations" left join "implementation_policy" on "implementations"."id" = "implementation_policy"."implementation_id" where not exists (select * from "policies" inner join "implementation_policy" on "policies"."id" = "implementation_policy"."policy_id" where "implementations"."id" = "implementation_policy"."implementation_id" and "policies"."id" = 1 and "policies"."deleted_at" is null) and "implementations"."deleted_at" is null limit 50) 

it seems that the select clause needs to be using the table name as well, e.g. Select distinct implementation.id ...

in the Application Menu: Attaching implementations to applications
in the asset menu: attaching implementations to assets works.
in the implementation menu: attaching policies to implementations works
in the risk menu, attaching a policy to a risk works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions