svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
930 stars 244 forks source link

NDB schema export doesn't work with SQLite #1157

Open pkulev opened 6 months ago

pkulev commented 6 months ago

I'm currently investigating another issue with NDB FDB. While reviewing https://docs.pyroute2.org/ndb_debug.html#rtnl-events to gather additional debug information, I encountered this 😅

In [103]: NDB().schema.export()
2023.12.24 19:26:01.114 ( events.py:0084): D: init
2023.12.24 19:26:01.115 ( source.py:0431): D: starting the source
2023.12.24 19:26:01.116 ( events.py:0084): D: init
2023.12.24 19:26:01.116 ( source.py:0431): D: starting the source
2023.12.24 19:26:01.117 ( events.py:0084): D: connecting
2023.12.24 19:26:01.117 ( events.py:0084): D: loading
2023.12.24 19:26:01.118 ( events.py:0084): D: connecting
2023.12.24 19:26:01.122 ( events.py:0084): D: loading
2023.12.24 19:26:01.125 ( events.py:0084): D: running
2023.12.24 19:26:01.224 ( events.py:0084): D: running

table interfaces
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.9/site-packages/pyroute2/ndb/schema.py:515 in execute                     │
│                                                                                                  │
│    512 │   │   │   #                                                                             │
│    513 │   │   │   for _ in range(MAX_ATTEMPTS):                                                 │
│    514 │   │   │   │   try:                                                                      │
│ ❱  515 │   │   │   │   │   self.cursor.execute(*argv, **kwarg)                                   │
│    516 │   │   │   │   │   break                                                                 │
│    517 │   │   │   │   except (sqlite3.InterfaceError, sqlite3.OperationalError) as e:           │
│    518 │   │   │   │   │   self.log.debug('%s' % e)                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140057114806016 and this is thread id 140058015954752.
svinota commented 5 months ago

Two interfaces are available:

# sqlite backup
ndb.backup("file_name.db")

# same but without the shortcut
ndb.task_manager.db_back("file_name.db")

# the old export method
ndb.task_manager.db_export()

I should update the docs probably...

svinota commented 5 months ago

Shortly speaking all the published ndb.schema methods (with @publish decorator) are available as ndb.task_manager.db_*

svinota commented 5 months ago

Sorry for delays, I was a bit off track the last year, but coming back now.