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

When a grant already exists, return the appropriate response #243

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

eric-maynard
Copy link
Contributor

Description

In the event that the persistence layer fails due to a primary key conflict, we should translate this to an AlreadyExistException which maps to response 409. Currently, we are returning a 500.

Fixes #226

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

As we don't have a robust test setup for eclipselink-backed Polaris currently, I manually tested with the following setup:

      <property name="jakarta.persistence.jdbc.url"
        value="jdbc:postgresql://localhost:5432/db"/>
      <property name="jakarta.persistence.jdbc.user" value="polaris"/>
      <property name="jakarta.persistence.jdbc.password" value="test"/>
      <property name="jakarta.persistence.schema-generation.database.action" value="create"/>
      <property name="eclipselink.logging.level.sql" value="FINE"/>
      <property name="eclipselink.logging.parameters" value="true"/>
      <property name="eclipselink.persistence-context.flush-mode" value="auto"/>

I then created a duplicate grant:

./polaris \
      --access-token 'principal:root;realm:default-realm' \
      catalogs \
      create example_catalog \
      --storage-type file \
      --default-base-location 'file:///tmp/example'

./polaris \
      --access-token 'principal:root;realm:default-realm' \
      principals \
      create \
      example_user

./polaris \
      --access-token 'principal:root;realm:default-realm' \
      principal-roles \
      create \
      example_user_role

./polaris \
      --access-token 'principal:root;realm:default-realm' \
      principal-roles \
      grant \
      --principal example_user \
      example_user_role

./polaris \
      --access-token 'principal:root;realm:default-realm' \
      principal-roles \
      grant \
      --principal example_user \
      example_user_role

This PR fixes the 500 and causes Polaris to return a 409:

./polaris \
>       --access-token 'principal:root;realm:default-realm' \
>       principal-roles \
>       grant \
>       --principal example_user \
>       example_user_role
Exception when communicating with the Polaris server. AlreadyExistsException: Grant already exists

Checklist:

Please delete options that are not relevant.

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

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] creating an existing principal role assignment returns 500 instead of 409
2 participants