Skip to content

Commit

Permalink
fix: insert on uuid with default value (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-vogel authored Nov 25, 2024
1 parent 50ebd10 commit 545e489
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db-service/lib/fill-in-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const generateUUIDandPropagateKeys = (entity, data, event) => {
if (event === 'CREATE') {
const keys = entity.keys
for (const k in keys)
if (keys[k].isUUID && !data[k] && !assoc4(keys[k])) //> skip key assocs, and foreign keys thereof
if (keys[k].isUUID && !data[k] && !assoc4(keys[k]) && !keys[k].default) //> skip key assocs, and foreign keys thereof
data[k] = cds.utils.uuid()
}
for (const each in entity.elements) {
Expand Down
2 changes: 1 addition & 1 deletion test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ entity C : managed {
toB : Composition of many B
on toB.ID = $self.B;
};
entity BooksAnnotated as projection on Books;
entity BooksAnnotated as projection on Books;
1 change: 1 addition & 0 deletions test/compliance/resources/db/basic/common.cds
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ entity temporal : _cuid, _temporal {}

// Set default values for all literals from ./literals.cds
entity ![default] : _cuid {
uuidDflt : UUID default '00000000-0000-0000-4000-000000000000';
bool : Boolean default false;
integer8 : UInt8 default 8;
integer16 : Int16 default 9;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const dstring = size => ({ d: 'default'.slice(0, size), o: 'not default'.slice(0, size) })

const columns = {
uuidDflt: { d: '00000000-0000-0000-4000-000000000000', o: '11111111-1111-1111-4111-111111111111'},
bool: { d: false, o: true },
integer8: { d: 8, o: 18 },
integer16: { d: 9, o: 19 },
Expand Down
1 change: 0 additions & 1 deletion test/scenarios/bookshop/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ describe('Bookshop - Insert', () => {
expect(written.price).to.be.eq(entry.price)
}
})

})

0 comments on commit 545e489

Please sign in to comment.