Skip to content

Fix namespace on newly created XML elements in library and deployment#18

Open
sclaiborne wants to merge 1 commit into
mainfrom
claude/upbeat-mclean-b879e3
Open

Fix namespace on newly created XML elements in library and deployment#18
sclaiborne wants to merge 1 commit into
mainfrom
claude/upbeat-mclean-b879e3

Conversation

@sclaiborne
Copy link
Copy Markdown
Member

What changed

Four ET.Element / ET.SubElement calls were creating elements without the Automation Studio namespace prefix, so the new elements were invisible to find/findall queries until the file was written to disk and re-read.

File Method Element
aspython/library.py addDependency <Dependencies> container
aspython/library.py _createDependencyElement <Dependency> child
aspython/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 _convertXmlTag in library.py.

_createDependencyElement was a @staticmethod; it becomes a regular instance method to access self.nameSpaceFormatted.

Why

xmlAsFile.findall prepends 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_roundtrip and tests/test_deployment.py::test_deploy_library_adds_entry. Both assert that the mutated state is visible in-memory immediately after the call, with no write() / read() cycle in between.

Reviewer notes

  • No behaviour change beyond fixing the silent namespace mismatch — callers that relied on the write+reload workaround still work because the file is written as before.
  • _addRootLevelElement (used by SwDeploymentTable.__init__) has the same pattern but is out of scope for this PR.

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.
@sclaiborne sclaiborne changed the base branch from main to refactor/aspython-package May 5, 2026 17:50
Base automatically changed from refactor/aspython-package to main May 5, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant