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

Forbid regex types and arrays in document's _id field #1326

Merged
merged 40 commits into from
Oct 31, 2022

Conversation

noisersup
Copy link
Member

@noisersup noisersup commented Oct 26, 2022

Description

Closes #1235.

Readiness checklist

  • I added tests for new functionality or bugfixes.
  • I ran task all, and it passed.
  • I added/updated comments for both exported and unexported top-level declarations (functions, types, etc).
  • I checked comments rendering with task godocs.
  • I ensured that the title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Assignee, Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

@vercel
Copy link

vercel bot commented Oct 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ferret-db ✅ Ready (Inspect) Visit Preview Oct 31, 2022 at 10:42AM (UTC)

@vercel vercel bot temporarily deployed to Preview October 26, 2022 13:07 Inactive
@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #1326 (c562129) into main (9d827c4) will increase coverage by 20.74%.
The diff coverage is 80.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1326       +/-   ##
===========================================
+ Coverage   46.63%   67.37%   +20.74%     
===========================================
  Files         279      279               
  Lines       13134    13141        +7     
===========================================
+ Hits         6125     8854     +2729     
+ Misses       6273     3365     -2908     
- Partials      736      922      +186     
Impacted Files Coverage Δ
internal/handlers/common/errorcode_string.go 80.00% <ø> (ø)
internal/handlers/pg/msg_update.go 62.43% <0.00%> (+62.43%) ⬆️
internal/types/document.go 87.77% <ø> (+9.51%) ⬆️
internal/handlers/common/error.go 80.00% <54.54%> (+56.92%) ⬆️
internal/types/document_validation.go 94.11% <95.23%> (+6.61%) ⬆️
internal/handlers/pg/msg_insert.go 52.11% <100.00%> (+52.11%) ⬆️
internal/handlers/tigris/msg_insert.go 64.51% <100.00%> (+15.28%) ⬆️
internal/util/version/version.go 48.52% <0.00%> (-4.42%) ⬇️
internal/clientconn/conn.go 44.70% <0.00%> (+0.68%) ⬆️
integration/helpers.go 87.23% <0.00%> (+1.06%) ⬆️
... and 60 more
Flag Coverage Δ
integration 63.46% <51.42%> (+26.18%) ⬆️
mongodb 14.25% <0.00%> (-0.05%) ⬇️
pg 52.95% <48.57%> (?)
tigris 34.94% <48.57%> (+0.28%) ⬆️
unit 26.06% <48.57%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@vercel vercel bot temporarily deployed to Preview October 26, 2022 13:53 Inactive
@vercel vercel bot temporarily deployed to Preview October 26, 2022 13:55 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 00:21 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 00:34 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 14:14 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 14:38 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 15:12 Inactive
@vercel vercel bot temporarily deployed to Preview October 27, 2022 15:33 Inactive
@noisersup noisersup changed the title forbid regex types and arrays in document's _id field Forbid regex types and arrays in document's _id field Oct 27, 2022
@vercel vercel bot temporarily deployed to Preview October 27, 2022 15:46 Inactive
@vercel vercel bot temporarily deployed to Preview October 28, 2022 17:02 Inactive
@vercel vercel bot temporarily deployed to Preview October 28, 2022 17:26 Inactive
@vercel vercel bot temporarily deployed to Preview October 28, 2022 17:40 Inactive
@vercel vercel bot temporarily deployed to Preview October 28, 2022 17:56 Inactive
@noisersup
Copy link
Member Author

Need a help with a linter. It screams about deprecation because of generating files, though we don't have any quick alternatives to the Map function and it's probably a topic for another issue. I tried to place //nolint:statickcheck but it said that the nolint is unused

@noisersup noisersup removed the do not merge PRs that should not be merged label Oct 30, 2022
@noisersup noisersup marked this pull request as ready for review October 30, 2022 00:32
Copy link
Member

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

I like the current implementation idea! Added a couple of comments (not super critical).

internal/handlers/common/error.go Outdated Show resolved Hide resolved
internal/types/document_validation.go Outdated Show resolved Hide resolved
internal/types/document_validation.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview October 31, 2022 10:04 Inactive
Copy link
Member

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

Looks good to me overall.

I think, one tiny thing could be improved in insert compat tests (see my comment), but as this task blocks some other things, I consider this request for changes minor.

Comment on lines +120 to +129
var targetFindRes, compatFindRes bson.D
targetCur, err := targetCollection.Find(ctx, bson.D{{}})
require.NoError(t, err)
targetCur.Decode(&targetFindRes)

compatCur, err := compatCollection.Find(ctx, bson.D{{}})
require.NoError(t, err)
compatCur.Decode(&targetFindRes)

AssertEqualDocuments(t, compatFindRes, targetFindRes)
Copy link
Member

Choose a reason for hiding this comment

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

Should we find by _id to compare inserted documents here? (The idea is to check that what we inserted is really stored equally).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that checking whole collection content is much more full-bodied. What if the insert function misbehaves and creates additional entry in collection? Checking only for specific _id would not cover this case

Copy link
Contributor

@chilagrow chilagrow left a comment

Choose a reason for hiding this comment

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

Seems good. I just have questions about skipped tests.

integration/insert_compat_test.go Show resolved Hide resolved
integration/insert_compat_test.go Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview October 31, 2022 10:42 Inactive
@w84thesun w84thesun enabled auto-merge (squash) October 31, 2022 11:17
@noisersup noisersup merged commit c55d8d4 into FerretDB:main Oct 31, 2022
@noisersup noisersup deleted the disallow-id-types-1235 branch October 31, 2022 11:17
@AlekSi AlekSi added this to the v0.6.1 milestone Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/enhancement Some user-visible feature could work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check that _id is not regex or array
5 participants