-
Notifications
You must be signed in to change notification settings - Fork 26
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: paginator generator nullability bug caused by documents #1155
Changes from 2 commits
6a7d4a5
9cb74f4
d2a225e
6854b9c
7344f7a
ced4b0a
73cc2bb
cd3ae1b
487d1fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "f71f083b-6e5f-4a3c-9069-464b1f9f6d36", | ||
"type": "bugfix", | ||
"description": "Fix paginator generator `List<Document>` nullability" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,18 +272,21 @@ private fun getItemDescriptorOrNull(paginationInfo: PaginationInfo, ctx: Codegen | |
val itemMember = ctx.model.expectShape(itemMemberId) | ||
val isSparse = itemMember.isSparse | ||
val (collectionLiteral, targetMember) = when (itemMember) { | ||
is MapShape -> | ||
ctx.symbolProvider.toSymbol(itemMember) | ||
.expectProperty(SymbolProperty.ENTRY_EXPRESSION) as String to itemMember | ||
is CollectionShape -> | ||
ctx.symbolProvider.toSymbol(ctx.model.expectShape(itemMember.member.target)).name to ctx.model.expectShape( | ||
itemMember.member.target, | ||
) | ||
is MapShape -> { | ||
val literal = ctx.symbolProvider.toSymbol(itemMember) | ||
.expectProperty(SymbolProperty.ENTRY_EXPRESSION) as String + if (isSparse) "?" else "" | ||
literal to itemMember | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Don't we also need to check if the symbol is nullable alongside the map being sparse? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the nullability of documents in this case is handled by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify a little bit? I'm confused why MapShape only checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, for The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's what we want. Your new unit test Note that there are two nullability modifiers:
A sparse map does not have missing entries, only missing values. I believe the logic needs to coalesce the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that too, we've been code-generating them like that so I wasn't 100% sure if it was wrong. The fix is in the PR now. |
||
is CollectionShape -> { | ||
val symbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(itemMember.member.target)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplification/duplication: |
||
val literal = symbol.name + if (symbol.isNullable || isSparse) "?" else "" | ||
literal to ctx.model.expectShape(itemMember.member.target) | ||
} | ||
else -> error("Unexpected shape type ${itemMember.type}") | ||
} | ||
|
||
return ItemDescriptor( | ||
collectionLiteral + if (isSparse) "?" else "", | ||
collectionLiteral, | ||
targetMember, | ||
itemLiteral, | ||
itemPathLiteral, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/clarification: This change does not only affect
List<Document>
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should only affect
List<Document>
types because they're the only type of list that can contain nullables without thesparse
trait being set on the list. Looking at KotlinSymbolProvider, document is the only symbol that always returnsasNullable()