loopbackio/loopback-connector-postgresql

invalid input syntax for type json when use repository.updateById()

zzhenryquezz opened this issue · 8 comments

Description/Steps to reproduce

When the dataType is JSON or JSONB and use repository.updateById() can't add the new array in database, but work normaly if use repository.replaceById()

Model:

@property({
    type: 'array',
    itemType: 'object',
    postgresql: {
      dataType: 'jsonb'
    },
    required: true,
  })
  test: AnyObject[];

Controller:

await this.testRepository.updateById(test_id, test);

Response:

invalid input syntax for type json

Sandbox

https://github.com/zzhenryquezz/bug-update-arrya-jsonb

Expected result

Update the array jsonb in Postgres Database

Additional information

Maybe is something related in the parse to JSON of the method updateById()

Edit: Steps to reproduce

1 - First config a postgres database in json connector

example-dbconfig

2 - Create a dummy data for the tests using the POST endpoint

example-post

3 - Try update one entity using the PATH endpoint
example-update

4 - This will trigger a Internar server error and also a error log in console
example-console-error

@raymondfeng @bajtos, it seems like a bug to me if it's working fine with repository.replaceById() but not repository.updateById(). What do you think?

It seems like a bug to me if it's working fine with repository.replaceById() but not repository.updateById().

Possibly.

Sandbox
https://github.com/zzhenryquezz/bug-update-arrya-jsonb

@zzhenryquezz Thank you for creating the reproduction app. I quickly skimmed through the code, but I don't see how are you invoking replaceById and updateById methods. What are the steps to reproduce the problem using your app?

Hi @bajtos I add the steps to reproduce in the issue description, should be more clear now.

I add the steps to reproduce in the issue description, should be more clear now.

Thank you @zzhenryquezz for the update. I am afraid I don't see those steps anywhere in your example app. Are you referring to Steps to reproduce section in the issue description?

@bajtos On this page, hover up and see, this is the last section of the comment.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.