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

Store.update() with $inc operator works incorrectly #1794

Closed
krutilin opened this issue Apr 7, 2021 · 0 comments
Closed

Store.update() with $inc operator works incorrectly #1794

krutilin opened this issue Apr 7, 2021 · 0 comments
Assignees
Labels
bug Issues related to defects and incorrect/unexpected feature behavior severity: major Issues with high impact on the product, e.g., new packages, installation issues, etc.

Comments

@krutilin
Copy link
Contributor

krutilin commented Apr 7, 2021

Store.update() with $inc operator works incorrectly and ignore try-catch in projection

To Reproduce

  1. npx create-resolve-app resolve-shopping-list-with-redux-hooks -e shopping-list-with-redux-hooks
  2. Change shopping-lists.projection
import {
  SHOPPING_LIST_CREATED,
  SHOPPING_LIST_REMOVED,
  SHOPPING_LIST_RENAMED,
} from '../event-types'

export default {
  Init: async (store) => {
    await store.defineTable('ShoppingLists', {
      indexes: {
        id: 'string',
      },
      fields: ['createdAt', 'name', 'props'],
    })
  },

  [SHOPPING_LIST_CREATED]: async (
    store,
    { aggregateId, timestamp, payload: { name } }
  ) => {
    try {
      const shoppingList = {
        id: aggregateId,
        name,
        createdAt: timestamp
      }

      await store.insert('ShoppingLists', shoppingList)
      await store.update(
        'ShoppingLists',
        { id: aggregateId },
        { $inc: { 'props.count': 1 } }
      )
    } catch (error) {
      console.log(error)
    }
  },

  [SHOPPING_LIST_REMOVED]: async (store, { aggregateId }) => {
    await store.delete('ShoppingLists', { id: aggregateId })
  },

  [SHOPPING_LIST_RENAMED]: async (
    store,
    { aggregateId, payload: { name } }
  ) => {
    await store.update('ShoppingLists', { id: aggregateId }, { $set: { name } })
  },
}
  1. Deploy app yarn resolve-cloud deploy --verbosity=trace
  2. Get error in logs
BadRequestException: ERROR: more than one row returned by a subquery used as an expression
    at Object.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12) {
  code: 'BadRequestException',
  time: 2021-04-07T09:20:07.652Z,
  requestId: '2c8ec3f3-ca98-4c6a-9143-354097af3e7e',
  statusCode: 400,
  retryable: false,
  retryDelay: 8.43247087180301
}
  1. And an error in the read models
BadRequestException: ERROR: current transaction is aborted, commands ignored until end of      
                                                                                                     transaction block     at Object.extractError                                                   
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)     at Request.extractError     
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)     at Request.callListeners
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)     at Request.emit      
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)     at Request.emit       
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)     at Request.transition            
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)     at AcceptorStateMachine.runTo     
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)     at                          
                                                                                                     /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10     at Request.<anonymous>        
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)     at Request.<anonymous>             
                                                                                                     (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)       

Expected behavior
Looks like 'more than one row returned by a subquery used as an expression' is an incorrect error for this case.
Read model should continue building if an error happened in the try-catch block.

@MrCheater MrCheater added severity: major Issues with high impact on the product, e.g., new packages, installation issues, etc. bug Issues related to defects and incorrect/unexpected feature behavior Component: readmodel-adapters labels Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to defects and incorrect/unexpected feature behavior severity: major Issues with high impact on the product, e.g., new packages, installation issues, etc.
Projects
None yet
Development

No branches or pull requests

4 participants