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

[Bug]: Ciscoconfparse2 doesn't support python pickle #12

Open
1 task done
mdeng10 opened this issue Aug 21, 2024 · 4 comments
Open
1 task done

[Bug]: Ciscoconfparse2 doesn't support python pickle #12

mdeng10 opened this issue Aug 21, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mdeng10
Copy link

mdeng10 commented Aug 21, 2024

Contact Details

No response

What happened?

CiscoConfParse objects don't support python's pickle module - this is a very handy module when you're working with 1000s of configs (it takes a long time to call CiscoConfParse() on this many objects)

I've had a look at the source code - it looks ike it's trying to save CiscoConfParse.config but it wasn't set during the __init__ - it looks like you can fix this by just specifying

self.config = config

during the __init__ here

it seems like CiscoConfParse.config should be set somewhere? it's entirely unused in this module it seems, perhaps a remnant of CiscoConfParse 1.0?

CiscoConfParse Version

0.7.74

What Operating System are you using?

MacOS

What Python version(s) have this problem?

Python 3.10

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

import pickle
from ciscoconfparse2 import CiscoConfParse

config_obj = CiscoConfParse(["Test config"], factory=True, syntax="ios")
pickle.dump(config_obj, open("test_data.pkl", "wb"))

Python tracebacks

Traceback (most recent call last):
  File "/redacted/path/main.py", line 247, in <module>
    lambda_function({}, {})
  File "/redacted/path/main.py", line 212, in lambda_function
    pickle.dump(configs, open("configs.pkl", "wb"))
  File "/redacted/path/venv/lib/python3.10/site-packages/attr/_make.py", line 1044, in slots_getstate
    return {name: getattr(self, name) for name in state_attr_names}
  File "/redacted/path/venv/lib/python3.10/site-packages/attr/_make.py", line 1044, in <dictcomp>
    return {name: getattr(self, name) for name in state_attr_names}
AttributeError: 'CiscoConfParse' object has no attribute 'config'

Relevant log output

No response

Code of Conduct

@mdeng10 mdeng10 added the bug Something isn't working label Aug 21, 2024
@mdeng10
Copy link
Author

mdeng10 commented Aug 21, 2024

seems like there might be more than i've detailed - when attempting to load a pickled object i hit a AttributeError: 'ConfigList' object has no attribute 'data' error which gets stuck into an infinite loop (or recursion loop) and crashes

i didn't have this problem in ciscoconfparse 1.0 - i'm unsure what specifically changed but will try to look further into it

@mdeng10
Copy link
Author

mdeng10 commented Aug 21, 2024

looks like it's only an issue when i'm in debugging mode in my IDE and i have a breakout that contains a ciscoconfparse object, likewise if i print it, it also throws an exception

but if i don't have breakpoints and just let the code run, no issues - very weird, this is most likely beyond me

@mpenning
Copy link
Owner

mpenning commented Aug 21, 2024

One problem is that attrs does not support this Optional[] typing syntax...

@attrs.define(repr=False)
class CiscoConfParse(object): 
    """Parse Cisco IOS configurations and answer queries about the configs."""
    config: Optional[Union[str,List[str]]] = None

There are a number of things that have to be fixed for CiscoConfParse() pickling / un-pickling to work... for now, consider it unsupported and it won't be fixed anytime soon. It also looks like I can't use attrs on BaseCfgLine() if I want un-pickling to work correctly.

@mdeng10
Copy link
Author

mdeng10 commented Aug 22, 2024

There are a number of things that have to be fixed for CiscoConfParse() pickling / un-pickling to work... for now, consider it unsupported

That's fair enough - feel free to close this issue or just keep it open for tracking so others don't re-raise 😄

@mpenning mpenning self-assigned this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants