Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing connection request data mutates it #148

Open
sajith opened this issue Sep 3, 2024 · 0 comments · May be fixed by #149
Open

Importing connection request data mutates it #148

sajith opened this issue Sep 3, 2024 · 0 comments · May be fixed by #149
Assignees

Comments

@sajith
Copy link
Member

sajith commented Sep 3, 2024

Consider this connection request:

request = {
    "name": "new-connection",
    "description": "a test circuit",
    "id": "7ab36e45-c041-4883-aceb-f391efa5866a",
    "endpoints": [
        {"port_id": "urn:sdx:port:amlight.net:A1:1", "vlan": "777"},
        {"port_id": "urn:sdx:port:amlight:B1:1", "vlan": "55:90"},
    ],
}

Passing this into ConnectionHandler.import_connection_data() can mutate the original request. Speficially, endpoints[n].port_id gets renamed to endpoints.id and endpoints[n].vlan becomes endpoints[n].vlan_range.

import pprint
from sdx_datamodel.parsing.connectionhandler import ConnectionHandler

ConnectionHandler().import_connection_data(request)
pprint.pprint(request)

The above code prints:

{'description': 'a test circuit',
 'endpoints': [{'id': 'urn:sdx:port:amlight.net:A1:1',
                'name': 'urn:sdx:port:amlight.net:A1:1',
                'vlan_range': 777},
               {'id': 'urn:sdx:port:amlight:B1:1',
                'name': 'urn:sdx:port:amlight:B1:1',
                'vlan_range': '55:90'}],
 'id': '7ab36e45-c041-4883-aceb-f391efa5866a',
 'name': 'new-connection'}

This is surprising behavior and mutating data like this makes it harder to reason about program behavior. Further, we'll be unable to access the original request, should we need it (such as when needing to look up disallowed VLANs: atlanticwave-sdx/pce#208). Although we still have the data we need in a slightly different form, switching things in this manner is probably not the best way to do this.

(ConnectionHandler._make_port() is the likely culprit. Perhaps using Pydantic to validate connection requests would be a good idea.)

@sajith sajith self-assigned this Sep 3, 2024
@sajith sajith linked a pull request Sep 3, 2024 that will close this issue
@sajith sajith linked a pull request Sep 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant