Pymongo update_one issue with nested fields

I have a document with nested objects in the following format:

{
    ...
    search_preferences: {
        ...
        bad_job_titles: []
    }
}

Now, we update the nested field using the update_one method and $set operator.

db[collection].update_one({"id": id}, {"$set": {"search_preferences.bad_job_titles": ["xyz"]}})

It works mostly, but sometimes in production we are seeing documents where instead of updating the bad_job_titles, there’s a separate field in the document as “search_preferences.bad_job_titles” in the follow format:

{
    ...
    search_preferences: {
        ...
        bad_job_titles: []
    },
    search_preferences.bad_job_titles: ["xyz"]
}

I have been scratching my head, but not sure what’s happening here, and why it would happen only to some documents.

In principal running the same code with the same data leads to the same results. I do not see any reason why $set would start to ignore the dot notation.

What I suspect is one of the following scenario:

1 - someone used Compass to create the field with the dot
2 - someone used $setField to create the field with the dot