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

Make constraint error details contain useful information for developers #6796

Merged
merged 10 commits into from
Feb 19, 2024

Conversation

aljazerzen
Copy link
Contributor

@aljazerzen aljazerzen commented Feb 7, 2024

Closes #6768

Changes error details of constraint violations to:

f'violated {constraint_description} on {subject_description}'

... where x_description is the x.get_verbosename()

@aljazerzen aljazerzen changed the title fix 7 Make constraint error details contain useful information for developers Feb 7, 2024
Comment on lines 629 to 631
# details is for the "developer" that must explain what's going on
# under the hood. It should be picked up from the errmessage on the
# first ancestor constraint that's in std module.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my initial approach for the details

Comment on lines +1161 to +1162
# edgedb-python does not expose a nicer access to details field
details = e._attrs[2].decode("utf-8")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am I doing something wrong here? Or does edgedb-python really don't expose error details field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out that edgedb-python really does not expose details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll wait for a release of edgedb-python and clean this up before merging.

@aljazerzen aljazerzen requested a review from msullivan February 7, 2024 16:54
@@ -599,6 +599,8 @@ def _interpret_constraint_errors(
# no need for else clause since it would have been handled by
# the static version

print(error_type)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(error_type)

Comment on lines 180 to 185
) -> List[Constraint]:
"""
Find the transitive closure of all constraints that apply.
Return parents of these constraints.
"""
# I'm not sure that this explanation is clear (or even entirely correct)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this explanation is quite right. I think it would be worth having clear documentation here, because there is a subtle issue at play.

The purpose of this function is to find which types an exclusive constraint originate from. If we have Baz <: Bar <: Foo, and Foo declares some exclusive constraint, then when we do an insert into Baz we need to check all Foos to make sure there is no conflict. (Which we do using triggers, and get_constraint_origin helps drive the generation of those.)

The subtleties here are:

  1. Because of multiple inheritance, we might have an exclusive constraint that originates from multiple unrelated ancestors
  2. Delegated exclusive constraints are declared on a parent, but their "origins" are their children. (So that abstract type Named or whatever can declare an exclusive name, but the names will be exclusive within each of the types that subtypes it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add these docs in a separate PR

@msullivan
Copy link
Member

Let's merge it without waiting for edgedb-python, so we can backport it without needing to bump edgedb-python on those branches

@aljazerzen aljazerzen merged commit 8c0e5f9 into master Feb 19, 2024
24 checks passed
@aljazerzen aljazerzen deleted the fix-7 branch February 19, 2024 08:51
CarsonF added a commit to SeedCompany/cord-api-v3 that referenced this pull request Apr 19, 2024
…new EdgeDB logic

Constraints were standardized with: geldata/gel#6796
So now I parse out all the dynamic parts of the message for all constraint errors.

I kept the subclass for now, but it could be replaced with the check
```diff
- e instanceof ExclusivityViolationError
+ e instanceof ConstraintViolationError && e.constraint === 'std::exclusive'
```
CarsonF added a commit to SeedCompany/cord-api-v3 that referenced this pull request Apr 19, 2024
…new EdgeDB logic

Constraints were standardized with: geldata/gel#6796
So now I parse out all the dynamic parts of the message for all constraint errors.

I kept the subclass for now, but it could be replaced with the check
```diff
- e instanceof ExclusivityViolationError
+ e instanceof ConstraintViolationError && e.constraint === 'std::exclusive'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

message and details fields are the same when you specify an errmessage for a constraint.
3 participants