Fix namespace on newly created XML elements in library and deployment#18
Open
sclaiborne wants to merge 1 commit into
Open
Fix namespace on newly created XML elements in library and deployment#18sclaiborne wants to merge 1 commit into
sclaiborne wants to merge 1 commit into
Conversation
ET.Element calls in addDependency, _createDependencyElement, _createLibraryElement, and _createTaskElement were missing the AS namespace prefix, so newly created elements were invisible to findall queries until the file was written and re-read. Prefix tags with self.nameSpaceFormatted so elements are findable in-memory immediately. Add tests that assert in-memory visibility after each mutating call, with no write+reload roundtrip required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Four
ET.Element/ET.SubElementcalls were creating elements without the Automation Studio namespace prefix, so the new elements were invisible tofind/findallqueries until the file was written to disk and re-read.aspython/library.pyaddDependency<Dependencies>containeraspython/library.py_createDependencyElement<Dependency>childaspython/deployment.py_createLibraryElement<LibraryObject>aspython/deployment.py_createTaskElement<Task>The fix prefixes each tag with
self.nameSpaceFormatted(e.g.{http://br-automation.co.at/AS/Library}), matching the approach already used by_convertXmlTaginlibrary.py._createDependencyElementwas a@staticmethod; it becomes a regular instance method to accessself.nameSpaceFormatted.Why
xmlAsFile.findallprepends the namespace to every XPath segment. Elements created without a namespace didn't match, causing silent failures that only resolved after a write+reload roundtrip.Tests
Added
tests/test_library.py::test_add_dependency_roundtripandtests/test_deployment.py::test_deploy_library_adds_entry. Both assert that the mutated state is visible in-memory immediately after the call, with nowrite()/read()cycle in between.Reviewer notes
_addRootLevelElement(used bySwDeploymentTable.__init__) has the same pattern but is out of scope for this PR.