diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-04-21 01:01:44 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-04-21 01:01:44 +0200 |
commit | cd5a980318d467206d30958073fa34fbb6a20f18 (patch) | |
tree | 41b9e6170832a3542a23356e1b49d778f39c7b39 | |
parent | 0b9a2ab6993b528dd5dab0beac9ec5c49d101bb9 (diff) | |
download | merchant-cd5a980318d467206d30958073fa34fbb6a20f18.tar.gz merchant-cd5a980318d467206d30958073fa34fbb6a20f18.tar.bz2 merchant-cd5a980318d467206d30958073fa34fbb6a20f18.zip |
-do not update total_sold when patching product, not provided as an argument, breaks invariants
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-products-ID.c | 3 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 17 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c b/src/backend/taler-merchant-httpd_private-patch-products-ID.c index 47f695af..f9f7bc67 100644 --- a/src/backend/taler-merchant-httpd_private-patch-products-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-products-ID.c @@ -57,6 +57,7 @@ determine_cause (struct MHD_Connection *connection, switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, @@ -87,6 +88,7 @@ determine_cause (struct MHD_Connection *connection, if (pd->total_stock - pdx.total_sold < pd->total_lost) ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_LOST_EXCEEDS_STOCKS; TALER_MERCHANTDB_product_details_free (&pdx); + GNUNET_break (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE != ec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_CONFLICT, ec, @@ -213,6 +215,7 @@ TMH_private_patch_products_ID (const struct TMH_RequestHandler *rh, switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); ret = TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 0170767d..cb9d1163 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1111,8 +1111,7 @@ postgres_update_product (void *cls, TALER_PQ_query_param_json (pd->taxes), TALER_PQ_query_param_amount (&pd->price), GNUNET_PQ_query_param_uint64 (&pd->total_stock), - GNUNET_PQ_query_param_uint64 (&pd->total_sold), - GNUNET_PQ_query_param_uint64 (&pd->total_lost), /* $11 */ + GNUNET_PQ_query_param_uint64 (&pd->total_lost), /* $10 */ TALER_PQ_query_param_json (pd->address), GNUNET_PQ_query_param_absolute_time (&pd->next_restock), GNUNET_PQ_query_param_end @@ -6315,20 +6314,18 @@ postgres_connect (void *cls) ",price_val=$8" ",price_frac=$9" ",total_stock=$10" - ",total_sold=$11" - ",total_lost=$12" - ",address=$13" - ",next_restock=$14" + ",total_lost=$11" + ",address=$12" + ",next_restock=$13" " WHERE merchant_serial=" " (SELECT merchant_serial" " FROM merchant_instances" " WHERE merchant_id=$1)" " AND product_id=$2" " AND total_stock <= $10" - " AND total_sold <= $11" - " AND $10 - $11 >= $12" - " AND total_lost <= $12", - 14), + " AND $10 - total_sold >= $11" + " AND total_lost <= $11", + 13), /* for postgres_lock_product() */ GNUNET_PQ_make_prepare ("lock_product", |