shuttle-hq / synth

The Declarative Data Generator
https://www.getsynth.com/
Apache License 2.0
1.37k stars 108 forks source link

Cannot insert numbers into postgresql `incorrect binary data format` #404

Closed CMCDragonkai closed 1 year ago

CMCDragonkai commented 1 year ago

Describe the bug

See title.

I'm using:

    "dob_year": {
      "type": "number",
      "optional": true,
      "subtype": "u32",
      "range": {
        "high": 2022,
        "low": 1900,
        "step": 1
      }
    },
    "dob_month": {
      "type": "number",
      "optional": true,
      "subtype": "u32",
      "range": {
        "high": 12,
        "low": 1,
        "step": 1
      }
    },

To Reproduce Steps to reproduce the behavior:

  1. Schema (if applicable)
    CREATE TABLE "customers" (
    "id" uuid DEFAULT gen_random_uuid(),
    "name" text NOT NULL,
    "email" text NOT NULL UNIQUE,
    "phone_number" text,
    "address_line_1" text,
    "address_line_2" text,
    "address_post_code" text,
    "address_state" text,
    "address_country" text,
    "dob_year" smallint CHECK (dob_year > 1900 AND dob_year <= 9999),
    "dob_month" smallint CHECK (dob_month > 0 AND dob_month <= 12),
    "notes" text NOT NULL DEFAULT '',
    "has_sms_allowed" boolean NOT NULL DEFAULT false,
    "has_email_allowed" boolean NOT NULL DEFAULT false,
    "created_on" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_on" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
    );
  2. See error
    
    [2022-12-15T08:57:39Z WARN  synth::datasource::relational_datasource] Trying to put an unsigned u32 into a int2 typed column customers.dob_month
    Error: At namespace "fixtures"

Caused by: 0: Failed to insert data for collection customers 1: One or more database inserts failed: error returned from database: incorrect binary data format in bind parameter 7: incorrect binary data format in bind parameter 7



**Expected behavior**

It should just insert the numbers.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
 - OS: [e.g. Linux, MacOS, Windows]
 - Version: 0.6.5

**Additional context**
Add any other context about the problem here.

---

Would be nice to see what the SQL is being generated to understand the problem.
iamwacko commented 1 year ago

int2 hasn't been implemented yet. This was first reported with #271.

CMCDragonkai commented 1 year ago

Why can't it just insert the number? The SQL expression looks the same whether it is a smallint or something else.

iamwacko commented 1 year ago

If you read the error closely you see error returned from database. The SQL expression's might look the same, but they aren't to the server.

iamwacko commented 1 year ago

int2 is now implemented in the codebase, but until the next release you will have to compile from source to get it to work.