dynamoxy 0.5.1__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/Cargo.lock +12 -13
  2. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/Cargo.toml +3 -3
  3. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/PKG-INFO +1 -1
  4. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/items.rs +1 -1
  5. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/mod.rs +37 -1
  6. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/table.rs +4 -4
  7. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/tests.rs +53 -0
  8. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/error.rs +38 -0
  9. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/lib.rs +4 -1
  10. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/src/client.rs +114 -30
  11. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/src/errors.rs +9 -0
  12. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/src/lib.rs +8 -0
  13. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/src/runtime.rs +44 -16
  14. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/AGENT_GUIDE.md +49 -14
  15. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/__init__.py +16 -2
  16. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/_core.pyi +21 -0
  17. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/_pydantic.py +129 -21
  18. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/attributes.py +56 -7
  19. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/batch.py +1 -0
  20. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/codecs.py +124 -5
  21. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/collection.py +92 -25
  22. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/errors.py +20 -0
  23. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/models.py +156 -21
  24. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/query.py +145 -68
  25. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/repository.py +294 -43
  26. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/schema.py +527 -37
  27. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/streams.py +32 -4
  28. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/table.py +44 -21
  29. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/testing.py +64 -5
  30. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/transactions.py +3 -0
  31. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/LICENSE +0 -0
  32. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/README.md +0 -0
  33. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/Cargo.toml +0 -0
  34. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/README.md +0 -0
  35. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/aws/convert.rs +0 -0
  36. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/aws/errors.rs +0 -0
  37. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/aws/mod.rs +0 -0
  38. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/admin.rs +0 -0
  39. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/batch.rs +0 -0
  40. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/partiql.rs +0 -0
  41. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/query.rs +0 -0
  42. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/memory/transact.rs +0 -0
  43. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/backend/mod.rs +0 -0
  44. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/client/tests.rs +0 -0
  45. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/client.rs +0 -0
  46. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/config.rs +0 -0
  47. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/events.rs +0 -0
  48. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/ast.rs +0 -0
  49. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/eval.rs +0 -0
  50. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/mod.rs +0 -0
  51. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/parser.rs +0 -0
  52. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/projection.rs +0 -0
  53. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/reserved.rs +0 -0
  54. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/tests.rs +0 -0
  55. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/expr/update.rs +0 -0
  56. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/metrics.rs +0 -0
  57. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/retry.rs +0 -0
  58. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/types/mod.rs +0 -0
  59. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/types/ops.rs +0 -0
  60. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/types/schema.rs +0 -0
  61. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/value/mod.rs +0 -0
  62. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/value/number.rs +0 -0
  63. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/src/value/size.rs +0 -0
  64. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-core/tests/emulator.rs +0 -0
  65. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/Cargo.toml +0 -0
  66. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/crates/dynamoxy-py/src/convert.rs +0 -0
  67. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/pyproject.toml +0 -0
  68. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/__main__.py +0 -0
  69. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/_utils.py +0 -0
  70. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/client.py +0 -0
  71. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/constraints.py +0 -0
  72. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/events.py +0 -0
  73. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/expressions.py +0 -0
  74. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/middleware.py +0 -0
  75. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/py.typed +0 -0
  76. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/results.py +0 -0
  77. {dynamoxy-0.5.1 → dynamoxy-0.6.0}/python/dynamoxy/telemetry.py +0 -0
@@ -658,7 +658,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
658
658
 
659
659
  [[package]]
660
660
  name = "dynamoxy-core"
661
- version = "0.5.1"
661
+ version = "0.6.0"
662
662
  dependencies = [
663
663
  "async-trait",
664
664
  "aws-config",
@@ -675,7 +675,7 @@ dependencies = [
675
675
 
676
676
  [[package]]
677
677
  name = "dynamoxy-py"
678
- version = "0.5.1"
678
+ version = "0.6.0"
679
679
  dependencies = [
680
680
  "dynamoxy-core",
681
681
  "parking_lot",
@@ -1127,9 +1127,9 @@ dependencies = [
1127
1127
 
1128
1128
  [[package]]
1129
1129
  name = "libc"
1130
- version = "0.2.190"
1130
+ version = "0.2.191"
1131
1131
  source = "registry+https://github.com/rust-lang/crates.io-index"
1132
- checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
1132
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
1133
1133
 
1134
1134
  [[package]]
1135
1135
  name = "litemap"
@@ -1139,9 +1139,9 @@ checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
1139
1139
 
1140
1140
  [[package]]
1141
1141
  name = "lock_api"
1142
- version = "0.4.14"
1142
+ version = "0.5.0"
1143
1143
  source = "registry+https://github.com/rust-lang/crates.io-index"
1144
- checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
1144
+ checksum = "65d91b22da179613dcf4d6ec8349563f52a363f6849e03b00dd0a185ec4a59af"
1145
1145
  dependencies = [
1146
1146
  "scopeguard",
1147
1147
  ]
@@ -1201,9 +1201,9 @@ checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e"
1201
1201
 
1202
1202
  [[package]]
1203
1203
  name = "parking_lot"
1204
- version = "0.12.5"
1204
+ version = "0.13.0"
1205
1205
  source = "registry+https://github.com/rust-lang/crates.io-index"
1206
- checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
1206
+ checksum = "a9cf937ca4e1d0b7578784559063422fc39ae7c5a00f02471f2614d5486fd226"
1207
1207
  dependencies = [
1208
1208
  "lock_api",
1209
1209
  "parking_lot_core",
@@ -1211,11 +1211,10 @@ dependencies = [
1211
1211
 
1212
1212
  [[package]]
1213
1213
  name = "parking_lot_core"
1214
- version = "0.9.12"
1214
+ version = "0.10.0"
1215
1215
  source = "registry+https://github.com/rust-lang/crates.io-index"
1216
- checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
1216
+ checksum = "9cfff060068cc18aa7815010fcaf80c68c7fb9e85fc7f5c0f9bf142c21d19826"
1217
1217
  dependencies = [
1218
- "cfg-if",
1219
1218
  "libc",
1220
1219
  "redox_syscall",
1221
1220
  "smallvec",
@@ -1354,9 +1353,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
1354
1353
 
1355
1354
  [[package]]
1356
1355
  name = "redox_syscall"
1357
- version = "0.5.18"
1356
+ version = "0.9.5"
1358
1357
  source = "registry+https://github.com/rust-lang/crates.io-index"
1359
- checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
1358
+ checksum = "580c875845b41ecb1564ad1ae4703044cef774145e3d7a94dc2b3fa7c97868fd"
1360
1359
  dependencies = [
1361
1360
  "bitflags",
1362
1361
  ]
@@ -4,7 +4,7 @@ members = ["crates/dynamoxy-core", "crates/dynamoxy-py"]
4
4
 
5
5
  # The single version of the project: the Python package takes it from the binding crate.
6
6
  [workspace.package]
7
- version = "0.5.1"
7
+ version = "0.6.0"
8
8
  edition = "2024"
9
9
  rust-version = "1.99"
10
10
  license = "MIT"
@@ -13,7 +13,7 @@ homepage = "https://github.com/kalaspuff/dynamoxy"
13
13
  authors = ["Carl Oscar Aaro <hello@carloscar.com>"]
14
14
 
15
15
  [workspace.dependencies]
16
- dynamoxy-core = { path = "crates/dynamoxy-core", version = "0.5.1" }
16
+ dynamoxy-core = { path = "crates/dynamoxy-core", version = "0.6.0" }
17
17
  async-trait = "0.1"
18
18
  aws-config = { version = "1.12", features = ["behavior-version-latest"] }
19
19
  aws-credential-types = { version = "1.3", features = ["hardcoded-credentials"] }
@@ -29,7 +29,7 @@ fastrand = "2"
29
29
  # Only to recognize the SDK's failures to connect (`legacy::Error::is_connect`): the same version
30
30
  # as the SDK's HTTP client, which Cargo unifies.
31
31
  hyper-util = { version = "0.1", default-features = false, features = ["client-legacy"] }
32
- parking_lot = "0.12"
32
+ parking_lot = "0.13"
33
33
  pyo3 = { version = "0.29", features = ["abi3-py312"] }
34
34
  pythonize = "0.29"
35
35
  serde = { version = "1", features = ["derive"] }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamoxy
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Framework :: AsyncIO
6
6
  Classifier: Framework :: Pydantic :: 2
@@ -298,7 +298,7 @@ pub fn update_item(state: &mut State, input: UpdateItemInput) -> Result<WriteIte
298
298
  // DynamoDB holds an update to 400 KB by what its request carries before it reads the item
299
299
  // (captured by dynoxide-rs, src/actions/update_item.rs).
300
300
  if update.request_charge() > MAX_ITEM_SIZE {
301
- return Err(Error::validation_exception("Item size to update has exceeded the maximum allowed size"));
301
+ return Err(Error::validation_exception(crate::error::UPDATE_SIZE_MESSAGE));
302
302
  }
303
303
  }
304
304
  let mut meter = CapacityMeter::default();
@@ -41,7 +41,7 @@ use crate::types::{
41
41
  DeleteItemInput, ExecuteStatementInput, ExecuteStatementOutput, ExecuteTransactionInput, ExecuteTransactionOutput,
42
42
  GetItemInput, GetItemOutput, ListBackupsInput, ListBackupsOutput, ListTablesInput, ListTablesOutput,
43
43
  ListTagsOutput, PutItemInput, QueryInput, QueryOutput, RestoreTableFromBackupInput, RestoreTableToPointInTimeInput,
44
- ScanInput, TableDescription, TimeToLiveDescription, TransactGetItemsInput, TransactGetItemsOutput,
44
+ ScanInput, TableDescription, TableStatus, TimeToLiveDescription, TransactGetItemsInput, TransactGetItemsOutput,
45
45
  TransactWriteItemsInput, TransactWriteItemsOutput, UpdateItemInput, UpdateTableInput, UpdateTimeToLiveInput,
46
46
  WriteItemOutput,
47
47
  };
@@ -274,6 +274,42 @@ impl MemoryBackend {
274
274
  deleted
275
275
  }
276
276
 
277
+ /// Deletes every item of every table, and every backup, idempotency token and pending fault.
278
+ /// The tables keep their keys, indexes, capacity, Time to Live and other settings, so tests can
279
+ /// share them and start from empty tables.
280
+ pub fn clear(&self) {
281
+ let mut state = self.state.lock();
282
+ for table in state.tables.values_mut() {
283
+ table.items.clear();
284
+ for index in &mut table.indexes {
285
+ index.entries.clear();
286
+ }
287
+ }
288
+ state.backups.clear();
289
+ state.tokens.clear();
290
+ state.faults.clear();
291
+ }
292
+
293
+ /// Creates a table at once: `ACTIVE` with its indexes, and with Time to Live enabled on
294
+ /// `ttl_attribute`. Test setup, without the `CREATING` state that `CreateTable` reports first
295
+ /// (and without faults); the table is checked as `CreateTable` checks it.
296
+ pub fn create_table_active(
297
+ &self,
298
+ input: CreateTableInput,
299
+ ttl_attribute: Option<String>,
300
+ ) -> Result<TableDescription> {
301
+ if ttl_attribute.as_deref() == Some("") {
302
+ return Err(ServiceError::validation("TimeToLiveSpecification AttributeName must not be empty").into());
303
+ }
304
+ let name = input.table_name.clone();
305
+ let mut state = self.state.lock();
306
+ named("CreateTable", admin::create_table(&mut state, input))?;
307
+ let table = state.tables.get_mut(&name).expect("the table was just created");
308
+ table.describes_until_active = 0;
309
+ table.ttl_attribute = ttl_attribute;
310
+ Ok(table.describe(TableStatus::Active))
311
+ }
312
+
277
313
  /// Deletes every table and backup.
278
314
  pub fn reset(&self) {
279
315
  let mut state = self.state.lock();
@@ -466,9 +466,9 @@ impl Table {
466
466
  }
467
467
  if total > 0 && item_size(item) + total > MAX_ITEM_SIZE {
468
468
  return Err(invalid(if update {
469
- "Item size to update has exceeded the maximum allowed size"
469
+ crate::error::UPDATE_SIZE_MESSAGE
470
470
  } else {
471
- "Item size has exceeded the maximum allowed size"
471
+ crate::error::ITEM_SIZE_MESSAGE
472
472
  }));
473
473
  }
474
474
  Ok(())
@@ -508,9 +508,9 @@ impl Table {
508
508
  }
509
509
  if item_size(item) > MAX_ITEM_SIZE {
510
510
  return Err(invalid(if update {
511
- "Item size to update has exceeded the maximum allowed size"
511
+ crate::error::UPDATE_SIZE_MESSAGE
512
512
  } else {
513
- "Item size has exceeded the maximum allowed size"
513
+ crate::error::ITEM_SIZE_MESSAGE
514
514
  }));
515
515
  }
516
516
  for index in &self.indexes {
@@ -3046,3 +3046,56 @@ async fn names_values_and_messages_follow_dynamodb() {
3046
3046
  "One or more parameter values are not valid. The update expression attempted to update a secondary index key to a value that is not supported. The AttributeValue for a key attribute cannot contain an empty string value."
3047
3047
  );
3048
3048
  }
3049
+
3050
+ #[tokio::test]
3051
+ async fn clear_empties_the_tables_and_keeps_their_definitions() {
3052
+ let backend = backend_with_table().await;
3053
+ seed_query_data(&backend).await;
3054
+ backend
3055
+ .update_time_to_live(UpdateTimeToLiveInput {
3056
+ table_name: "items".into(),
3057
+ attribute_name: "expires".into(),
3058
+ enabled: true,
3059
+ })
3060
+ .await
3061
+ .unwrap();
3062
+ backend.create_backup("items", "before").await.unwrap();
3063
+ backend.inject_fault(Fault { operation: None, table: None, kind: FaultKind::Unprocessed, times: 5 });
3064
+ backend.clear();
3065
+ let description = backend.describe_table("items").await.unwrap();
3066
+ assert_eq!(description.table_status, TableStatus::Active);
3067
+ assert_eq!(description.item_count, 0);
3068
+ assert_eq!(description.global_secondary_indexes.len(), 1, "the indexes stay");
3069
+ assert!(backend.query(query("pk = :p", values(&[(":p", s("p"))]))).await.unwrap().items.is_empty());
3070
+ let by_status =
3071
+ QueryInput { index_name: Some("by_status".into()), ..query("#s = :s", values(&[(":s", s("even"))])) };
3072
+ let by_status = QueryInput { expression_attribute_names: names(&[("#s", "status")]), ..by_status };
3073
+ assert!(backend.query(by_status.clone()).await.unwrap().items.is_empty(), "and so do their entries");
3074
+ assert!(backend.list_backups(ListBackupsInput::default()).await.unwrap().backups.is_empty());
3075
+ let ttl = backend.describe_time_to_live("items").await.unwrap();
3076
+ assert_eq!(ttl.attribute_name.as_deref(), Some("expires"), "Time to Live stays enabled");
3077
+ // The faults are gone, and the table takes items again.
3078
+ seed_query_data(&backend).await;
3079
+ assert_eq!(backend.query(by_status).await.unwrap().items.len(), 5);
3080
+ }
3081
+
3082
+ #[tokio::test]
3083
+ async fn tables_created_at_once_are_active_with_their_ttl() {
3084
+ let backend = MemoryBackend::default();
3085
+ let description = backend.create_table_active(table_input("items"), Some("expires".into())).unwrap();
3086
+ assert_eq!(description.table_status, TableStatus::Active);
3087
+ let described = backend.describe_table("items").await.unwrap();
3088
+ assert_eq!(described.table_status, TableStatus::Active, "not CREATING first");
3089
+ assert!(described.global_secondary_indexes.iter().all(|index| index.index_status == Some(IndexStatus::Active)));
3090
+ assert_eq!(backend.describe_time_to_live("items").await.unwrap().attribute_name.as_deref(), Some("expires"));
3091
+ put(&backend, item([("pk", s("p")), ("sk", n(1))])).await;
3092
+ let again = backend.create_table_active(table_input("items"), None).unwrap_err();
3093
+ assert_eq!(code(&again), "ResourceInUseException");
3094
+ let mut bad = table_input("bad");
3095
+ bad.key_schema = keys("missing", None);
3096
+ assert_eq!(code(&backend.create_table_active(bad, None).unwrap_err()), "ValidationException");
3097
+ assert_eq!(
3098
+ code(&backend.create_table_active(table_input("x2"), Some(String::new())).unwrap_err()),
3099
+ "ValidationException"
3100
+ );
3101
+ }
@@ -244,6 +244,14 @@ impl ServiceError {
244
244
  Self::new("ValidationException", message)
245
245
  }
246
246
 
247
+ /// Whether this is DynamoDB's refusal of an item over its 400 KB limit (counted with the
248
+ /// item's entries in the table's local secondary indexes): a `ValidationException` whose
249
+ /// message is one of [`ITEM_SIZE_MESSAGES`], also inside the `1 validation error detected: `
250
+ /// envelope.
251
+ pub fn is_item_too_large(&self) -> bool {
252
+ self.kind == ErrorKind::Validation && is_item_size_message(&self.message)
253
+ }
254
+
247
255
  /// `ConditionalCheckFailedException`, with the old item if it was requested.
248
256
  pub fn conditional_check_failed(item: Option<Item>) -> Self {
249
257
  Self { item, ..Self::new("ConditionalCheckFailedException", "The conditional request failed") }
@@ -366,10 +374,40 @@ impl Error {
366
374
  }
367
375
  }
368
376
 
377
+ /// DynamoDB's message for an item over its 400 KB limit: of `PutItem`, `BatchWriteItem` and the
378
+ /// cancellation reasons of `TransactWriteItems` (measured in eu-north-1, docs/parity).
379
+ pub const ITEM_SIZE_MESSAGE: &str = "Item size has exceeded the maximum allowed size";
380
+
381
+ /// DynamoDB's message for an `UpdateItem` that makes an item exceed its 400 KB limit.
382
+ pub const UPDATE_SIZE_MESSAGE: &str = "Item size to update has exceeded the maximum allowed size";
383
+
384
+ /// DynamoDB's messages for an item over its 400 KB limit ([`ITEM_SIZE_MESSAGE`],
385
+ /// [`UPDATE_SIZE_MESSAGE`]).
386
+ pub const ITEM_SIZE_MESSAGES: [&str; 2] = [ITEM_SIZE_MESSAGE, UPDATE_SIZE_MESSAGE];
387
+
388
+ /// Whether `message` is (or holds) one of [`ITEM_SIZE_MESSAGES`].
389
+ pub fn is_item_size_message(message: &str) -> bool {
390
+ ITEM_SIZE_MESSAGES.iter().any(|known| message.contains(known))
391
+ }
392
+
369
393
  #[cfg(test)]
370
394
  mod tests {
371
395
  use super::*;
372
396
 
397
+ #[test]
398
+ fn item_size_refusals_are_recognized() {
399
+ assert!(ServiceError::validation("Item size has exceeded the maximum allowed size").is_item_too_large());
400
+ assert!(
401
+ ServiceError::validation("Item size to update has exceeded the maximum allowed size").is_item_too_large()
402
+ );
403
+ assert!(
404
+ ServiceError::validation("1 validation error detected: Item size has exceeded the maximum allowed size")
405
+ .is_item_too_large()
406
+ );
407
+ assert!(!ServiceError::validation("One or more parameter values were invalid").is_item_too_large());
408
+ assert!(!ServiceError::new("InternalServerError", ITEM_SIZE_MESSAGES[0]).is_item_too_large(), "not a refusal");
409
+ }
410
+
373
411
  #[test]
374
412
  fn codes_are_classified() {
375
413
  assert_eq!(ErrorKind::from_code("ProvisionedThroughputExceededException"), ErrorKind::Throttling);
@@ -23,7 +23,10 @@ pub mod value;
23
23
 
24
24
  pub use client::{BatchGetResult, BatchWriteResult, Call, Client, OperationStats};
25
25
  pub use config::{ClientConfig, RetryConfig};
26
- pub use error::{CancellationReason, Error, ErrorKind, Result, ServiceError};
26
+ pub use error::{
27
+ CancellationReason, Error, ErrorKind, ITEM_SIZE_MESSAGE, ITEM_SIZE_MESSAGES, Result, ServiceError,
28
+ UPDATE_SIZE_MESSAGE, is_item_size_message,
29
+ };
27
30
  pub use value::{AttributeValue, Item, Number};
28
31
 
29
32
  /// Version of the core crate.
@@ -471,6 +471,107 @@ impl PyMemoryStore {
471
471
  fn reset(&self) {
472
472
  self.backend.reset();
473
473
  }
474
+
475
+ /// Deletes every item of every table, and every backup, idempotency token and pending fault;
476
+ /// the tables keep their keys, indexes and settings.
477
+ fn clear(&self) {
478
+ self.backend.clear();
479
+ }
480
+
481
+ /// Creates a table at once, without awaiting: `ACTIVE` with its indexes, and with Time to
482
+ /// Live enabled on `ttl_attribute`. It takes `CreateTable`'s arguments, like
483
+ /// `CoreClient.create_table`, and returns the table's description.
484
+ #[pyo3(signature = (table_name, *, attribute_definitions, key_schema, local_secondary_indexes = Vec::new(), global_secondary_indexes = Vec::new(), billing_mode = "PAY_PER_REQUEST", provisioned_throughput = None, on_demand_throughput = None, stream_specification = None, sse_specification = None, tags = PyStrMap::default(), table_class = None, deletion_protection_enabled = false, ttl_attribute = None))]
485
+ #[allow(clippy::too_many_arguments)]
486
+ fn create_table(
487
+ &self,
488
+ py: Python<'_>,
489
+ table_name: String,
490
+ attribute_definitions: Vec<(String, String)>,
491
+ key_schema: (String, Option<String>),
492
+ local_secondary_indexes: Vec<LocalIndexArg>,
493
+ global_secondary_indexes: Vec<GlobalIndexArg>,
494
+ billing_mode: &str,
495
+ provisioned_throughput: Option<(i64, i64)>,
496
+ on_demand_throughput: Option<(Option<i64>, Option<i64>)>,
497
+ stream_specification: Option<(bool, Option<String>)>,
498
+ sse_specification: Option<(bool, Option<String>, Option<String>)>,
499
+ tags: PyStrMap,
500
+ table_class: Option<&str>,
501
+ deletion_protection_enabled: bool,
502
+ ttl_attribute: Option<String>,
503
+ ) -> PyResult<Py<PyAny>> {
504
+ let input = create_table_input(
505
+ table_name,
506
+ attribute_definitions,
507
+ key_schema,
508
+ local_secondary_indexes,
509
+ global_secondary_indexes,
510
+ billing_mode,
511
+ provisioned_throughput,
512
+ on_demand_throughput,
513
+ stream_specification,
514
+ sse_specification,
515
+ tags,
516
+ table_class,
517
+ deletion_protection_enabled,
518
+ )?;
519
+ let description =
520
+ self.backend.create_table_active(input, ttl_attribute).map_err(|error| error_in(py, error))?;
521
+ table_output(py, description)
522
+ }
523
+ }
524
+
525
+ /// The `CreateTableInput` of `CreateTable`'s arguments (of `CoreClient.create_table` and
526
+ /// `MemoryStore.create_table`).
527
+ #[allow(clippy::too_many_arguments)]
528
+ fn create_table_input(
529
+ table_name: String,
530
+ attribute_definitions: Vec<(String, String)>,
531
+ key_schema: (String, Option<String>),
532
+ local_secondary_indexes: Vec<LocalIndexArg>,
533
+ global_secondary_indexes: Vec<GlobalIndexArg>,
534
+ billing_mode: &str,
535
+ provisioned_throughput: Option<(i64, i64)>,
536
+ on_demand_throughput: Option<(Option<i64>, Option<i64>)>,
537
+ stream_specification: Option<(bool, Option<String>)>,
538
+ sse_specification: Option<(bool, Option<String>, Option<String>)>,
539
+ tags: PyStrMap,
540
+ table_class: Option<&str>,
541
+ deletion_protection_enabled: bool,
542
+ ) -> PyResult<CreateTableInput> {
543
+ Ok(CreateTableInput {
544
+ table_name,
545
+ attribute_definitions: attribute_definitions
546
+ .into_iter()
547
+ .map(|(name, kind)| {
548
+ Ok(AttributeDefinition { name, attribute_type: constant!(&kind, ScalarType, "attribute type")? })
549
+ })
550
+ .collect::<PyResult<_>>()?,
551
+ key_schema: self::key_schema(key_schema),
552
+ local_secondary_indexes: local_secondary_indexes
553
+ .into_iter()
554
+ .map(|index| {
555
+ Ok(LocalSecondaryIndex {
556
+ index_name: index.index_name,
557
+ key_schema: self::key_schema(index.key_schema),
558
+ projection: projection(index.projection)?,
559
+ })
560
+ })
561
+ .collect::<PyResult<_>>()?,
562
+ global_secondary_indexes: global_secondary_indexes
563
+ .into_iter()
564
+ .map(GlobalIndexArg::into_core)
565
+ .collect::<PyResult<_>>()?,
566
+ billing_mode: constant!(billing_mode, BillingMode, "billing_mode")?,
567
+ provisioned_throughput: throughput(provisioned_throughput),
568
+ on_demand_throughput: on_demand(on_demand_throughput),
569
+ stream_specification: stream(stream_specification)?,
570
+ sse_specification: sse(sse_specification),
571
+ tags: tags.0,
572
+ table_class: optional_constant(table_class, |value| constant!(value, TableClass, "table_class"))?,
573
+ deletion_protection_enabled,
574
+ })
474
575
  }
475
576
 
476
577
  #[pyclass(name = "CoreClient", module = "dynamoxy._core", frozen)]
@@ -1197,38 +1298,21 @@ impl PyCoreClient {
1197
1298
  deletion_protection_enabled: bool,
1198
1299
  ) -> PyResult<Bound<'py, PyAny>> {
1199
1300
  let client = self.client()?;
1200
- let input = CreateTableInput {
1301
+ let input = create_table_input(
1201
1302
  table_name,
1202
- attribute_definitions: attribute_definitions
1203
- .into_iter()
1204
- .map(|(name, kind)| {
1205
- Ok(AttributeDefinition { name, attribute_type: constant!(&kind, ScalarType, "attribute type")? })
1206
- })
1207
- .collect::<PyResult<_>>()?,
1208
- key_schema: self::key_schema(key_schema),
1209
- local_secondary_indexes: local_secondary_indexes
1210
- .into_iter()
1211
- .map(|index| {
1212
- Ok(LocalSecondaryIndex {
1213
- index_name: index.index_name,
1214
- key_schema: self::key_schema(index.key_schema),
1215
- projection: projection(index.projection)?,
1216
- })
1217
- })
1218
- .collect::<PyResult<_>>()?,
1219
- global_secondary_indexes: global_secondary_indexes
1220
- .into_iter()
1221
- .map(GlobalIndexArg::into_core)
1222
- .collect::<PyResult<_>>()?,
1223
- billing_mode: constant!(billing_mode, BillingMode, "billing_mode")?,
1224
- provisioned_throughput: throughput(provisioned_throughput),
1225
- on_demand_throughput: on_demand(on_demand_throughput),
1226
- stream_specification: stream(stream_specification)?,
1227
- sse_specification: sse(sse_specification),
1228
- tags: tags.0,
1229
- table_class: optional_constant(table_class, |value| constant!(value, TableClass, "table_class"))?,
1303
+ attribute_definitions,
1304
+ key_schema,
1305
+ local_secondary_indexes,
1306
+ global_secondary_indexes,
1307
+ billing_mode,
1308
+ provisioned_throughput,
1309
+ on_demand_throughput,
1310
+ stream_specification,
1311
+ sse_specification,
1312
+ tags,
1313
+ table_class,
1230
1314
  deletion_protection_enabled,
1231
- };
1315
+ )?;
1232
1316
  self.run(py, async move { finish(client.create_table(input).await, table_output) })
1233
1317
  }
1234
1318
 
@@ -4,6 +4,7 @@
4
4
  //! DynamoxyError .retryable .code .message .operation .request_id .status_code
5
5
  //! ├── ConfigurationError invalid client configuration
6
6
  //! ├── ValidationError invalid request (local, or DynamoDB's ValidationException)
7
+ //! │ └── ItemTooLargeError an item over DynamoDB's 400 KB limit
7
8
  //! ├── ServiceError any other error returned by DynamoDB
8
9
  //! │ ├── ConditionalCheckFailedError .item (the old item when requested)
9
10
  //! │ ├── TransactionCanceledError .reasons [(code, message, item), ...]
@@ -48,6 +49,12 @@ create_exception!(
48
49
  DynamoxyError,
49
50
  "An invalid request, detected locally or by DynamoDB."
50
51
  );
52
+ create_exception!(
53
+ dynamoxy.errors,
54
+ ItemTooLargeError,
55
+ ValidationError,
56
+ "An item (with its entries in the table's local indexes) is over DynamoDB's 400 KB limit."
57
+ );
51
58
  create_exception!(dynamoxy.errors, ServiceError, DynamoxyError, "An error returned by DynamoDB.");
52
59
  create_exception!(
53
60
  dynamoxy.errors,
@@ -160,6 +167,7 @@ fn build(py: Python<'_>, error: Error) -> PyResult<PyErr> {
160
167
  let err = match &error {
161
168
  Error::Config(message) => ConfigurationError::new_err(message.clone()),
162
169
  Error::Validation(message) => ValidationError::new_err(message.clone()),
170
+ Error::Service(service) if service.is_item_too_large() => ItemTooLargeError::new_err(service.to_string()),
163
171
  Error::Service(service) => service_class(service.kind)(service.to_string()),
164
172
  Error::Transport { .. } => TransportError::new_err(error.to_string()),
165
173
  Error::OutcomeUnknown { .. } => WriteOutcomeUnknownError::new_err(error.to_string()),
@@ -214,6 +222,7 @@ pub fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
214
222
  ("DynamoxyError", py.get_type::<DynamoxyError>()),
215
223
  ("ConfigurationError", py.get_type::<ConfigurationError>()),
216
224
  ("ValidationError", py.get_type::<ValidationError>()),
225
+ ("ItemTooLargeError", py.get_type::<ItemTooLargeError>()),
217
226
  ("ServiceError", py.get_type::<ServiceError>()),
218
227
  ("ConditionalCheckFailedError", py.get_type::<ConditionalCheckFailedError>()),
219
228
  ("TransactionCanceledError", py.get_type::<TransactionCanceledError>()),
@@ -66,6 +66,13 @@ fn is_reserved_word(name: &str) -> bool {
66
66
  reserved::is_reserved(name)
67
67
  }
68
68
 
69
+ /// Whether `message` is DynamoDB's refusal of an item over its 400 KB limit (the cancellation
70
+ /// reasons of transactions carry it too).
71
+ #[pyfunction]
72
+ fn is_item_size_message(message: &str) -> bool {
73
+ dynamoxy_core::is_item_size_message(message)
74
+ }
75
+
69
76
  /// Validates expressions with the same parser as the in-memory backend (raises
70
77
  /// `ValidationError` like DynamoDB would). Used by tests of the expression builder.
71
78
  #[pyfunction]
@@ -154,6 +161,7 @@ fn _core(m: &Bound<'_, PyModule>) -> PyResult<()> {
154
161
  m.add_function(wrap_pyfunction!(value_to_wire, m)?)?;
155
162
  m.add_function(wrap_pyfunction!(value_from_wire, m)?)?;
156
163
  m.add_function(wrap_pyfunction!(is_reserved_word, m)?)?;
164
+ m.add_function(wrap_pyfunction!(is_item_size_message, m)?)?;
157
165
  m.add_function(wrap_pyfunction!(_check_expressions, m)?)?;
158
166
  m.add_function(wrap_pyfunction!(_apply_update, m)?)?;
159
167
  m.add_function(wrap_pyfunction!(_reset_after_fork, m)?)?;