API returning ghost associations

I’m having problems with ghost associations, the API it’s returning associations which doesn’t exist.
In the application, I have only one association, but the API returns old associations which don’t exist anymore.

Request code:

import hubspot
from pprint import pprint
from hubspot.crm.associations import BatchInputPublicObjectId, ApiException

client = hubspot.Client.create(api_key="")

batch_input_public_object_id = BatchInputPublicObjectId(inputs=[{"id":"4471025044"}])
try:
 api_response = client.crm.associations.batch_api.read(from_object_type="deal", to_object_type="company", batch_input_public_object_id=batch_input_public_object_id)
 pprint(api_response)
except ApiException as e:
 print("Exception when calling batch_api->read: %s\n" % e)

Response

{
 "status": "COMPLETE",
 "results": [
 {
 "from": {
 "id": "4471025044"
 },
 "to": [
 {
 "id": "422817697",
 "type": "deal_to_company"
 },
 {
 "id": "3152074442",
 "type": "deal_to_company"
 }
 ]
 }
 ],
 "startedAt": "2022-01-12T13:52:37.907Z",
 "completedAt": "2022-01-12T13:52:37.915Z"
}

I don’t know if it could have an impact, but those companies have a parent relationship, but also the actively associated companie have parent association with others.
The API v4 response it’s correct, but since it’s in beta I can’t apply these on our production pipelines.

{
 "results": [
 {
 "toObjectId": 422817697,
 "associationTypes": [
 {
 "category": "HUBSPOT_DEFINED",
 "typeId": 5,
 "label": "Primary"
 }
 ]
 },
 {
 "toObjectId": 3152074442,
 "associationTypes": [
 {
 "category": "HUBSPOT_DEFINED",
 "typeId": 5,
 "label": "Primary"
 }
 ]
 }
 ]

@himanshurauthan ,

have you experienced anything like this?

Hey guys, talking with Hubspot support I was able to understand better why this is happening.
It happened because two deals, associated with two different companies were merged, so when you merge two deals it’s supposed to carry all old associations, but since deals can be associated only with one company, the frontend shows one company, but in the backend, it has two companies associated.
Now I’m trying to report this bug.

That’s great you found the solution.