Skip to content

Conversation

@kkthxbye-code
Copy link
Contributor

Fixes: #11226

This PR intends to fix cases where script and utility code loaded from subpackages wasn't getting reloaded after changes were made.

The way this is done, is by taking the base module path (the string before the first dot), so if a script module import path is my_submodule.my_script_file.MyScriptClass we would delete any module from sys.modules where the base my_submodule matches.

Furthermore we remove any module from sys.modules where the base path equals scripts. This was added, because utility functions imported via. the normal import statement, would be imported like:

from scripts.util.util_file import util_function

Which would be present in sys.modules as:

scripts.util.util_file

Removing all modules from the cache which starts with scripts solves this issue, and from my testing causes no other issues. I tested this as well as I could, with the main focus being the default value for SCRIPT_ROOT. Subpackage importing when using a non-default SCRIPT_ROOT is still not great, but outside the scope of this PR.

In short you can now modify the following without reloading netbox or the rqworker:

  • The name of the script class in subpackages
  • Script variables in subpackages
  • Imported utility functions

@kkthxbye-code kkthxbye-code force-pushed the 11226-fix-script-reloading branch from 8a5e09e to a778ef1 Compare February 16, 2023 11:46
@jeremystretch
Copy link
Member

Awesome, kicked this around a bit and it seems to work great. Thanks @kkthxbye-code!

@jeremystretch jeremystretch merged commit c78022a into netbox-community:develop Feb 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom scripts in sub packages should not be cached

2 participants