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
Postgres TypeError: Converting circular structure to JSON #6999
Comments
Can you create a repository that exhibits this? I can't replicate it with TypeORM natively. |
Sure, I have pushed the monorepo that I have to github Maybe it is a nestjs/typeorm issue and not just typeorm but I'm unable to to figure out the code that would be causing a problem other than typeorm itself. Also, I've never really had this issue before so I am not sure how else I can reproduce it. |
We have the same problem. It occurs when we call This is how our entities look like: @Unique("UK_uid", ["uid"])
@Entity("party")
export class PartyEntity {
constructor(id: string, type: PartyType, uid: string) {
this.id = id
this.type = type
this.uid = uid
}
@PrimaryGeneratedColumn('uuid')
id: string
@Column({
type: "enum",
enum: PartyType
})
type: PartyType
@Column()
uid: string
@OneToMany(() => PartyContactEntity, partyContact => partyContact.party, {cascade: true})
contacts: PartyContactEntity[]
} @Entity("customer_contact")
export class PartyContactEntity {
constructor(party: PartyEntity, contactMedium: ContactMediumEntity) {
this.party = party;
this.contactMedium = contactMedium;
}
@PrimaryColumn('uuid', {name: "party_id"})
@ManyToOne(() => PartyEntity, party => party.contacts)
party: PartyEntity
@PrimaryColumn('uuid', {name: "contact_id"})
@OneToOne(() => ContactMediumEntity)
@JoinColumn({name: "contact_id", referencedColumnName: "id"})
contactMedium: ContactMediumEntity
} Is there an error in how we've built our entities? |
It happens in TypeORM 0.2.22 and 0.2.18 as well. |
@ErolPeel When saving a One-to-Many relation in TypeORM you need to be careful to only reference one side of the relation. For example when you want to save a PartyEntity with a PartyContactEntity, do it like this: const partyContactEntity: PartyContactEntity = new PartyContactEntity()
partyContactEntity.contactMedium = savedPostalContactEntity.contactMedium
// important: do not set the partyContactEntity.party here as this will result in the
// "TypeError: Converting circular structure to JSON" error when saving the contact with the party
const partyEntity: PartyEntity = new PartyEntity( ... )
partyEntity.contacts = [partyContactEntity]
manager.save(partyEntity) |
Hi got the same error message but on a different context (using createQueryBuilder) I resolved this by adding either : |
Issue Description
So I am using postgresql with typeorm and nestjs and I have a user entity. When I run
.findOne({username })
it works fine, but doing.find({})
to get all simply gives this error:Expected Behavior
The following code should return the list of users to the backend:
Actual Behavior
It errors with circular socket structure error:
Steps to Reproduce
My Environment
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: