I've had this on many more modern vehicles. So both BMW and Porsche recommend when disconnecting the batter follow these procedures. So far they have worked on other brands as well and this includes my Grenadier.
Before starting work:
Unlock vehicle, roll down windows and open access to battery trunk or frunk. Place towel over latch so it cannot accidently close. (in our case its rear passenger doors.)
Remove the key from the vehicle, keep unmoved for the entire time of work. ( I placed mine in a cabinet inside the home where it would not be disturbed).
Once the following two items are complete let vehicle sit till it goes to sleep. Indicators for this would be lights go off, dash goes dark, no indicator lights are on. ( This seems to be somewhere between 10-30 mins depending on which car I work on)
Remove the negative battery connection first or only. (depending on the work you might only have to remove the negative side)
Perform work, if work does not require battery to be disconnected for more than 30mins let vehicle sit without reconnecting battery for a 30min time window. (Also no movement of the key itself)
Reconnect battery allow system to fall back to sleep before getting the key and returning vehicle to operation.
I've follow this on all my modern vehicles and have never had issues like stated above. However before I learned this process I too had to get codes cleared and other hard resets. Just my two cents of what has been successful for me.
