Skip to content

Commit b5bcf15

Browse files
authored
Merge pull request #79 from purkhusid/empty-string
Allow empty strings
2 parents fe86d3c + 688212c commit b5bcf15

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ type StringPickler() =
3636
override _.Pickle s =
3737
if isNull s then
3838
AttributeValue(NULL = true)
39-
elif s = "" then
40-
invalidOp "empty strings not supported by DynamoDB."
4139
else
4240
AttributeValue(s)
4341
|> Some

tests/FSharp.AWS.DynamoDB.Tests/RecordGenerationTests.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ module ``Record Generation Tests`` =
3030
test <@ r' = r @>
3131
with
3232
// account for random inputs not supported by the library
33-
| :? InvalidOperationException as e when e.Message = "empty strings not supported by DynamoDB." -> ()
3433
| :? ArgumentException as e when
35-
e.Message.Contains "unsupported key name" && e.Message.Contains "should be 1 to 64k long (as utf8)"
36-
->
34+
e.Message.Contains "unsupported key name" && e.Message.Contains "should be 1 to 64k long (as utf8)" ->
3735
()
3836

3937
Check.One(config, roundTrip)

tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module SimpleTableTypes =
1818
[<RangeKey>]
1919
RangeKey: string
2020

21+
EmptyString: string
22+
2123
Value: int64
2224

2325
Tuple: int64 * int64
@@ -46,6 +48,7 @@ type ``Simple Table Operation Tests``(fixture: TableFixture) =
4648
let mkItem () =
4749
{ HashKey = guid ()
4850
RangeKey = guid ()
51+
EmptyString = ""
4952
Value = rand ()
5053
Tuple = rand (), rand ()
5154
Map = seq { for _ in 0L .. rand () % 5L -> "K" + guid (), rand () } |> Map.ofSeq
@@ -131,6 +134,23 @@ type ``Simple Table Operation Tests``(fixture: TableFixture) =
131134
test <@ None = deletedItem @>
132135
test <@ not (table.ContainsKey key) @>
133136

137+
[<Theory>]
138+
[<InlineData("",
139+
"rangeKey",
140+
"One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: HashKey")>]
141+
[<InlineData("hashKey",
142+
"",
143+
"One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: RangeKey")>]
144+
[<InlineData("",
145+
"",
146+
"One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: HashKey")>]
147+
let ``Operations with empty key values should fail with a DynamoDB client error`` (hashKey, rangeKey, expectedErrorMsg) =
148+
let value = { mkItem () with HashKey = hashKey; RangeKey = rangeKey }
149+
try
150+
table.PutItem value |> ignore
151+
with :? Amazon.DynamoDBv2.AmazonDynamoDBException as ex ->
152+
test <@ ex.Message = expectedErrorMsg @>
153+
134154
interface IClassFixture<TableFixture>
135155

136156
type ``TransactWriteItems tests``(fixture: TableFixture) =
@@ -139,6 +159,7 @@ type ``TransactWriteItems tests``(fixture: TableFixture) =
139159
let mkItem () =
140160
{ HashKey = guid ()
141161
RangeKey = guid ()
162+
EmptyString = ""
142163
Value = rand ()
143164
Tuple = rand (), rand ()
144165
Map = seq { for _ in 0L .. rand () % 5L -> "K" + guid (), rand () } |> Map.ofSeq

0 commit comments

Comments
 (0)