Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Policy patch - leave fields unchanged if they're missing from request#64174

Merged
antonsviridov-src merged 6 commits into
mainfrom
GRAPH-782/fix-syntactic-policy-gql-resolver
Aug 1, 2024
Merged

Policy patch - leave fields unchanged if they're missing from request#64174
antonsviridov-src merged 6 commits into
mainfrom
GRAPH-782/fix-syntactic-policy-gql-resolver

Conversation

@antonsviridov-src

@antonsviridov-src antonsviridov-src commented Jul 31, 2024

Copy link
Copy Markdown
Contributor

Fixes GRAPH-782

Specifically this allows us avoid updating syntactic_indexing_enabled when we don't have the value available.

This is done to solve the problem where not providing that field crashes the resolver. I confirmed it by both via tests and via manual testing of the API
CleanShot 2024-07-31 at 15 51 54

Test plan

  • Added a new test for resolvers specifically to test the extra logic around this field

Changelog

Specifically this allows us avoid updating syntactic_indexing_enabled
when we don't have the value available.
@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@antonsviridov-src

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

The GitHub CLA Bot is rechecking to see that you have signed the CLA - note that it may take up to 30 minutes for your response to be synchronized.

@antonsviridov-src

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

The GitHub CLA Bot is rechecking to see that you have signed the CLA - note that it may take up to 30 minutes for your response to be synchronized.

@jhchabran

Copy link
Copy Markdown
Contributor

@cla-bot check

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

The GitHub CLA Bot is rechecking to see that you have signed the CLA - note that it may take up to 30 minutes for your response to be synchronized.

@jhchabran

Copy link
Copy Markdown
Contributor

@cla-bot check

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement (CLA), and we don't have yours on file. In order for us to review and merge your code, please sign CLA to get yourself added.

Sourcegraph teammates should refer to Accepting contributions for guidance.

@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

The GitHub CLA Bot is rechecking to see that you have signed the CLA - note that it may take up to 30 minutes for your response to be synchronized.

@jhchabran

Copy link
Copy Markdown
Contributor

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Jul 31, 2024
@cla-bot

cla-bot Bot commented Jul 31, 2024

Copy link
Copy Markdown

The GitHub CLA Bot is rechecking to see that you have signed the CLA - note that it may take up to 30 minutes for your response to be synchronized.

@antonsviridov-src antonsviridov-src marked this pull request as ready for review July 31, 2024 14:28
retain_intermediate_commits = %s,
indexing_enabled = %s,
syntactic_indexing_enabled = %s,
syntactic_indexing_enabled = COALESCE(%s, p.syntactic_indexing_enabled),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not push the nullability of the GraphQL API this deep. Afaict at the call site we have access to the previous record, so we should be able to do the merging in Go code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this is the callsite - all we have is the constructed patch struct from the graphql args: https://github.com/sourcegraph/sourcegraph/pull/64174/files#diff-84bf2c19aa6cbb0438b9bbfb47f4eba71b981a3f4b9318f63d4f02895639a186R91-R100

unless I'm missing something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 how did I miss that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only issue is that it's not going to be atomic, but I seriously hope people don't blast policy update endpoint with concurrent requests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +25 to +41
type ConfigurationPolicyPatch struct {
ID int
RepositoryID *int
RepositoryPatterns *[]string
Name string
Type GitObjectType
Pattern string
Protected bool
RetentionEnabled bool
RetentionDuration *time.Duration
RetainIntermediateCommits bool
PreciseIndexingEnabled bool
SyntacticIndexingEnabled *bool
IndexCommitMaxAge *time.Duration
IndexIntermediateCommits bool
EmbeddingEnabled bool
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-ish: Maybe we could extract the shared part into a struct and make the patch:

ConfigurationPolicyPatch = ConfigurationPolicyShared + Option[bool]
ConfigurationPolicyEntity = ConfigurationPolicyShared + bool

that should also let you avoid some of the spurious changes in policies/service.go by passing around the shared struct.
Using Option over * let's us be more explicit as well (some of the ptrs in here are not about optionality afaict

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hope is that eventually (after a minor release possibly) we can remove the special status from syntactic indexing field, remove its optionality and either

  1. promote patch to actually useful struct by relaxing the API and making lots more fields optional
  2. remove patch if relaxing the API doesn't make sense

In case of (1) I would like to use options instead, yes.

@kritzcreek kritzcreek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking comment was addressed

@antonsviridov-src antonsviridov-src merged commit 7aba473 into main Aug 1, 2024
@antonsviridov-src antonsviridov-src deleted the GRAPH-782/fix-syntactic-policy-gql-resolver branch August 1, 2024 11:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants