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

Error when snapshot exists with an underscore in the name #2388

Closed
coloursofnoise opened this issue Jun 19, 2024 · 1 comment · Fixed by #2391
Closed

Error when snapshot exists with an underscore in the name #2388

coloursofnoise opened this issue Jun 19, 2024 · 1 comment · Fixed by #2391

Comments

@coloursofnoise
Copy link

Creating a snapshot with an underscore in the name (e.g. test_snapshot) results in an error when trying to load the snapshot after the server has restarted:

Traceback (most recent call last):
  File "/home/gns3/.venv/gns3server-venv/lib/python3.8/site-packages/gns3server/web/route.py", line 202, in control_schema
    func(request, response)
  File "/home/gns3/.venv/gns3server-venv/lib/python3.8/site-packages/gns3server/handlers/api/controller/snapshot_handler.py", line 67, in list
    response.json(sorted(snapshots, key=lambda s: (s.created_at, s.name)))
  File "/home/gns3/.venv/gns3server-venv/lib/python3.8/site-packages/gns3server/handlers/api/controller/snapshot_handler.py", line 67, in <lambda>
    response.json(sorted(snapshots, key=lambda s: (s.created_at, s.name)))
  File "/home/gns3/.venv/gns3server-venv/lib/python3.8/site-packages/gns3server/controller/snapshot.py", line 80, in created_at
    return int(self._created_at)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'

This is because the snapshot name is parsed by assuming that everything following the first underscore is the date:

self._name = filename.split("_")[0]
datestring = filename.replace(self._name + "_", "").split(".")[0]

A more robust solution might be to simply work backwards from the end of the filename instead using negative indexing:

-self._name = filename.split("_")[0]
+self._name = filename.split("_")[:-2].join("_")
 datestring = filename.replace(self._name + "_", "").split(".")[0] 
@grossmj grossmj linked a pull request Jul 5, 2024 that will close this issue
@grossmj
Copy link
Member

grossmj commented Jul 5, 2024

Thanks, the issue is fixed now.

@grossmj grossmj closed this as completed Jul 5, 2024
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 a pull request may close this issue.

2 participants