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

Edit Creates New Records Instead of Updating #10

Open
noahsettersten opened this issue Feb 18, 2020 · 2 comments
Open

Edit Creates New Records Instead of Updating #10

noahsettersten opened this issue Feb 18, 2020 · 2 comments

Comments

@noahsettersten
Copy link

Hello,

We've encountered an issue where editing any record in AdminBro doesn't update the existing record, but actually inserts a new record in the database. So when we edit an item, we duplicate it with the same data (and a new generated ID primary key) instead of editing the existing item. This happens on any of our TypeORM entities, and it still occurs even with the simplified version I've posted below.

Here is a video demonstrating the issue: https://share.getcloudapp.com/kpuYod9O

No error is printed in the console, and AdminBro displays success in saving the record. I'm using a forked version of admin-bro-typeorm to avoid the problem in issue #5.

To rule out any issue with our versions of AdminBro or our configuration, I set up a basic Sequelize model for this same table and used the AdminBro Sequelize adapter. The issue does not happen there and is only specific to the TypeORM adapter.

Versions Used

  1. admin-bro: 1.6.6
  2. admin-bro-expressjs: 0.4.0
  3. admin-bro-typeorm: Forked version of 1.6-alpha.8 (https://github.com/headwayio/admin-bro-typeorm)
  4. typeorm: 0.2.22

We're running on Postgres 10 in Docker.

AdminBro Options

import { Database, Resource } from 'admin-bro-typeorm';
AdminBro.registerAdapter({ Database, Resource });

const adminBro = new AdminBro({
    resources: [{ resource: TaxNexusRegion }],
    rootPath: '/admin',
});

TaxNexusRegion TypeORM Entity

import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  BaseEntity,
} from 'typeorm';

@Entity('tax_nexus_region')
export class TaxNexusRegion extends BaseEntity {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'id',
  })
  id: string;

  @Column('character varying', {
    nullable: false,
    name: 'region',
  })
  region: string;

  @Column('character varying', {
    nullable: false,
    name: 'region_code',
  })
  region_code: string;

  @Column('character varying', {
    nullable: false,
    name: 'country',
  })
  country: string;

  @Column('character varying', {
    nullable: false,
    name: 'country_code',
  })
  country_code: string;

  @Column('timestamp with time zone', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'created',
  })
  created: Date;

  @Column('timestamp with time zone', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'updated',
  })
  updated: Date;
}
@noahsettersten noahsettersten changed the title Edit creates new Records instead of updating Edit Creates New Records Instead of Updating Feb 18, 2020
@Arteha
Copy link
Owner

Arteha commented Feb 27, 2020

Use admin-bro 1.6.0 instead of 1.6.6.
1.6.0+ versions are not stable.

@noahsettersten
Copy link
Author

Thanks for the information.

Unfortunately, that didn't resolve the issue for my app. I've attempted with both admin-bro 1.6.0 and 1.5.2, and they both exhibit the same issue here.

I also reverted admin-bro-typeorm to 0.1.5, but that produced an entirely different error:
invalid input syntax for integer: "undefined"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants