venantius / darg

Kill the status meeting -- an abandoned IDoneThis competitor.
1 stars 0 forks source link

Resolve fixture loading bug #198

Open venantius opened 9 years ago

venantius commented 9 years ago

There's a bug at the moment wherein bad fixtures will get sorta loaded and the underlying exception will be hidden. So to be specific, as of 5e6c5206245fead4e1a4d332b8c3afa5827320f3 we have the following: https://github.com/ursacorp/darg/blob/master/test/darg/fixtures/model.clj#L41 where a user has a :surname field set. Problem is, the table doesn't actually have a surname field.

This actually throws an exception, but what we see in practice is that korma ends up successfully inserting all required fields (e.g. not-null), but failing to insert non-required fields (for instance, test-user-4's github-user-id field).

We should modify the code to catch this sort of warning or exception and surface it, and then fail hard.

venantius commented 9 years ago

Fwiw this exception IS printed at the REPL:

user=> (darg.fixtures.db/insert-user-fixture-data)
Failure to execute query with SQL:
INSERT INTO "users" ("active", "admin", "email", "name", "password", "surname", "tzorp") VALUES (?, ?, ?, ?, ?, ?, ?)  ::  [true false test@darg.io LSP $2a$10$iLkMks5MgNJ9d33x1qWSsOTyKYsW4rnWcSK4dnRMNgYVbmR9ZTs9O Smith false]
PSQLException:
 Message: ERROR: column "surname" of relation "users" does not exist
  Position: 70
 SQLState: 42703
 Error Code: 0

PSQLException ERROR: column "surname" of relation "users" does not exist
  Position: 70  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2157)```
venantius commented 9 years ago

Okay, so here's the final outcome on this. Had to look at the Korma source code to figure out what's going on.

Korma looks at the keys found in the first map in a vector of maps passed in as values to be inserted, and assumes that those are the only keys that matter. It then only grabs those keys from the remaining maps to be inserted.

This means that if our fixture data doesn't explicitly include nils for non-initialized fields for at the very least the first of each type, korma will just drop the data for those fields for all remaining records on the floor.