Giter VIP home page Giter VIP logo

id-transformation-issue's Introduction

Minimum Reproducible Example for Id transformation error

Steps to run this project:

  1. Run npm i command
  2. Run docker compose up to bootstrap a local instance of the database
  3. Run npm test command to see the test failing

The error

graph LR
  A(User)
  B(User Repository)
  C(Address)
  D(Typeorm)
  E["QueryFailedError: invalid input syntax for type integer: value:18"]
  A -- "Has Many" --> C
  C -- "Belongs To One" --> A
  D -- "Save" --> B
  B -- "Cascade save operation" --> E

Problem Description

We're experiencing an issue with the TypeORM library in the context of saving entities with relations.

Our application uses a Value Object Id for the id attribute in each model. To correctly manage this, we employ the transform option in the entity schemas (please refer to the UserSchema and AddressSchema code snippets). This transformation is defined in the idTransformer function.

The User entity has a one-to-many relation to the Address entity. As such, when a new User is created and saved, we attempt to add an Address object to this user and save it again. This is done in the hope that the address entity would be persisted in the database as part of a cascading save operation.

Unfortunately, during the second save operation, the application throws the error QueryFailedError: invalid input syntax for type integer: "{"value":18}".

Investigation shows that this issue arises because TypeORM does not appear to execute the idTransformer during the cascading save operation for the Address entity. As a result, the transformation of the id value from Id type to integer (expected by TypeORM and the underlying database) does not occur.

The Mermaid chart above provides a visualization of the process and the point at which the issue occurs. The User object is defined and provided an Address object. When the User entity is saved for the second time, we expect a cascading save operation to persist the Address object to the database. However, this is when the QueryFailedError is triggered.

We appreciate any assistance in resolving this issue. The error interrupts a core functionality of our application and we're keen on a prompt resolution.

id-transformation-issue's People

Contributors

thiagomini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.