Proof of concept working towards fixing T48975
Using this patch, a ID property group now stores a reference to the struct that owns it and its type in unused fields of IDProperty::data. This reference is propagated to any property that is added to an IDP_GROUP or IDP_IDPARRAY. rna_path_from_ID_to_idpgroup() uses this ownership reference if it exists to search for the ID property in the right place and to build a path.
Creating and updating the reference after loading a file happens in the idprops() function for each type. It was the easiest place to do add that, otherwise RNA stuff would have to be added in places that doesn't deal with RNA. I can see how something might go wrong here but so far haven't encountered any problems.
The attached patch is a proof of concept and shouldn't be seen as a patch to be committed immediately. My question is if this is acceptable as an approach since it is kind of a hack (but on the other hand the way ID properties are stored already looks like a hack to me).