Make sure dynamic objects can be saved and reloaded
# What does this PR do?

Fixes #20884 

This PR makes sure that models that use the code on the Hub feature can be saved and repushed while still including the necessary code files. as reported in #20884, this was not the case previously. The fix is simple enough and the tests have been extended to test this use case.
_The documentation is not available anymore as the PR was closed or merged._