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 the returned schema object for broken views #12713

Merged

Conversation

dbussink
Copy link
Contributor

The logic added in #12675 has a small issue. When a view is found that has an error, it's not present anymore when a subsequent .ToSQL() call happens, so it looks like the view disappears.

We should never have a view disappear since that could potentially break things and lead to unexpected results.

Related Issue(s)

Issue introduced in #12675

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

The logic added in vitessio#12675 has a
small issue. When a view is found that has an error, it's not present
anymore when a subsequent `.ToSQL()` call happens, so it looks like the
view disappears.

We should never have a view disappear since that could potentially break
things and lead to unexpected results.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink requested a review from deepthi as a code owner March 23, 2023 12:38
}
return schema, nil
err := schema.normalize()
return schema, err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small equivalent simplification here.

@@ -309,16 +307,18 @@ func (s *Schema) normalize() error {
// - two or more views have a circular dependency
for _, t := range s.tables {
if _, ok := dependencyLevels[t.Name()]; !ok {
// We _know_ that in this iteration, at least one view is found unassigned a dependency level.
// We _know_ that in this iteration, at least one foreign key is not found.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment was wrong here as well.

errs = errors.Join(errs, &ViewDependencyUnresolvedError{View: v.ViewName.Name.String()})
// We still add it so it shows up in the output if that is used for anything.
s.sorted = append(s.sorted, v)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the logic and the comment.

@dbussink dbussink merged commit 647a19e into vitessio:main Mar 23, 2023
@dbussink dbussink deleted the dbussink/fix-return-for-invalid-view branch March 23, 2023 15:32
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.

3 participants