-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue type:
[x] bug report
Database system/driver:
[x] postgres
TypeORM version:
[x] latest
Steps to reproduce or a small repository showing the problem:
// ./Doc.entity.ts
@Entity()
export class Doc {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column("varchar", {
length: 2000,
nullable: true,
// marshall
transformer: {
from(value: string | null): URL | null {
return value !== null ? new URL(value) : value;
},
to(value: URL | null): string | null {
return value?.toString() || null;
},
},
})
url: URL | null;
}
// elsewhere…
const doc = new Doc();
doc.url = new URL("https://typeorm.io/")
await repository.save(doc); // <- throws here with `TypeError: Cannot set property 'flags' of undefined`The stack trace suggests that Node internals for URL are throwing here
https://github.com/nodejs/node/blob/2fa74e3e38bb028339e48763138456b3ed10ed97/lib/internal/url.js#L240 (ctx is undefined?)
after href#set is called: https://github.com/nodejs/node/blob/2fa74e3e38bb028339e48763138456b3ed10ed97/lib/internal/url.js#L458
which is triggered from the TypeORM library here:
Line 90 in 685d76b
| Object.assign(target, { [key]: value }); |
I've previously employed richer types + transformers for other data types flawlessly. However, this data type (URL) fails before it even gets to the transformers to Marshall to the database.
I'm not familiar enough with the inner workings of how TypeORM serializes its data to break this problem down. Is there something about the URL data type specifically that prevents it from working as expected?
In the meantime, I can work with the data type as a string, and transform it to a URL manually.