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

AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension' #26

Open
tianze-hou opened this issue Nov 21, 2024 · 4 comments

Comments

@tianze-hou
Copy link

memos version: 0.19.2

$ memos init         
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/memos/commands.py:97 in init                                             │
│                                                                              │
│    94 │   """Initialize the database."""                                     │
│    95 │   from .models import init_database                                  │
│    96 │                                                                      │
│ ❱  97 │   db_success = init_database()                                       │
│    98 │   if db_success:                                                     │
│    99 │   │   print("Initialization completed successfully.")                │
│   100 │   else:                                                              │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/memos/models.py:256 in init_database                                     │
│                                                                              │
│   253 │   event.listen(engine, "connect", load_extension)                    │
│   254 │                                                                      │
│   255 │   try:                                                               │
│ ❱ 256 │   │   Base.metadata.create_all(engine)                               │
│   257 │   │   print(f"Database initialized successfully at {db_path}")       │
│   258 │   │                                                                  │
│   259 │   │   # Create FTS and Vec tables                                    │
│                                                                              │
│ ╭─────────────────────────── locals ───────────────────────────╮             │
│ │ db_path = '/Users/tianze/.memos/database.db'                 │             │
│ │  engine = Engine(sqlite:////Users/tianze/.memos/database.db) │             │
│ ╰──────────────────────────────────────────────────────────────╯             │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/sql/schema.py:5868 in create_all                              │
│                                                                              │
│   5865 │   │     in the target database.                                     │
│   5866 │   │                                                                 │
│   5867 │   │   """
│ ❱ 5868 │   │   bind._run_ddl_visitor(                                        │
│   5869 │   │   │   ddl.SchemaGenerator, self, checkfirst=checkfirst, tables= │
│   5870 │   │   )                                                             │
│   5871                                                                       │
│                                                                              │
│ ╭──────────────────────────── locals ─────────────────────────────╮          │
│ │       bind = Engine(sqlite:////Users/tianze/.memos/database.db) │          │
│ │ checkfirst = True                                               │          │
│ │       self = MetaData()                                         │          │
│ │     tables = None                                               │          │
│ ╰─────────────────────────────────────────────────────────────────╯          │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/engine/base.py:3252 in _run_ddl_visitor                       │
│                                                                              │
│   3249 │   │   element: SchemaItem,                                          │
│   3250 │   │   **kwargs: Any,                                                │
│   3251 │   ) -> None:                                                        │
│ ❱ 3252 │   │   with self.begin() as conn:                                    │
│   3253 │   │   │   conn._run_ddl_visitor(visitorcallable, element, **kwargs) │
│   3254 │                                                                     │
│   3255 │   def connect(self) -> Connection:                                  │
│                                                                              │
│ ╭─────────────────────────── locals ───────────────────────────╮             │
│ │ element = MetaData()                                         │             │
│ │  kwargs = {'checkfirst': True, 'tables': None}               │             │
│ │    self = Engine(sqlite:////Users/tianze/.memos/database.db) │             │
│ ╰──────────────────────────────────────────────────────────────╯             │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib │
│ .py:135 in __enter__                                                         │
│                                                                              │
│   132 │   │   # they are only needed for recreation, which is not possible a │
│   133 │   │   del self.args, self.kwds, self.func                            │
│   134 │   │   try:                                                           │
│ ❱ 135 │   │   │   return next(self.gen)                                      │
│   136 │   │   except StopIteration:                                          │
│   137 │   │   │   raise RuntimeError("generator didn't yield") from None     │
│   138                                                                        │
│                                                                              │
│ ╭────────────────────────────── locals ──────────────────────────────╮       │
│ │ self = <contextlib._GeneratorContextManager object at 0x10f80b700> │       │
│ ╰────────────────────────────────────────────────────────────────────╯       │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/engine/base.py:3242 in begin                                  │
│                                                                              │
│   3239 │   │   │   for a particular :class:`_engine.Connection`.             │
│   3240 │   │                                                                 │
│   3241 │   │   """                                                           │
│ ❱ 3242 │   │   with self.connect() as conn:                                  │
│   3243 │   │   │   with conn.begin():                                        │
│   3244 │   │   │   │   yield conn                                            │
│   3245                                                                       │
│                                                                              │
│ ╭───────────────────────── locals ──────────────────────────╮                │
│ │ self = Engine(sqlite:////Users/tianze/.memos/database.db) │                │
│ ╰───────────────────────────────────────────────────────────╯                │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/engine/base.py:3278 in connect                                │
│                                                                              │
│   3275 │   │                                                                 │
│   3276 │   │   """                                                           │
│   3277 │   │                                                                 │
│ ❱ 3278 │   │   return self._connection_cls(self)                             │
│   3279 │                                                                     │
│   3280 │   def raw_connection(self) -> PoolProxiedConnection:                │
│   3281 │   │   """Return a "raw" DBAPI connection from the connection pool.  │
│                                                                              │
│ ╭───────────────────────── locals ──────────────────────────╮                │
│ │ self = Engine(sqlite:////Users/tianze/.memos/database.db) │                │
│ ╰───────────────────────────────────────────────────────────╯                │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/engine/base.py:146 in __init__                                │
│                                                                              │
│    143 │   │                                                                 │
│    144 │   │   if connection is None:                                        │
│    145 │   │   │   try:                                                      │
│ ❱  146 │   │   │   │   self._dbapi_connection = engine.raw_connection()      │
│    147 │   │   │   except dialect.loaded_dbapi.Error as err:                 │
│    148 │   │   │   │   Connection._handle_dbapi_exception_noconnection(      │
│    149 │   │   │   │   │   err, dialect, engine                              │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │  _allow_autobegin = True                                                 │ │
│ │ _allow_revalidate = True                                                 │ │
│ │       _has_events = None                                                 │ │
│ │        connection = None                                                 │ │
│ │           dialect = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_… │ │
│ │                     object at 0x10f864700>                               │ │
│ │            engine = Engine(sqlite:////Users/tianze/.memos/database.db)   │ │
│ │              self = <sqlalchemy.engine.base.Connection object at         │ │
│ │                     0x10e600a30>                                         │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/engine/base.py:3302 in raw_connection                         │
│                                                                              │
│   3299 │   │   │   :ref:`dbapi_connections`                                  │
│   3300 │   │                                                                 │
│   3301 │   │   """                                                           │
│ ❱ 3302 │   │   return self.pool.connect()                                    │
│   3303                                                                       │
│   3304                                                                       │
│   3305 class OptionEngineMixin(log.Identified):                              │
│                                                                              │
│ ╭───────────────────────── locals ──────────────────────────╮                │
│ │ self = Engine(sqlite:////Users/tianze/.memos/database.db) │                │
│ ╰───────────────────────────────────────────────────────────╯                │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:449 in connect                                   │
│                                                                              │
│    446 │   │   the pool.                                                     │
│    447 │   │                                                                 │
│    448 │   │   """                                                           │
│ ❱  449 │   │   return _ConnectionFairy._checkout(self)                       │
│    450 │                                                                     │
│    451 │   def _return_conn(self, record: ConnectionPoolEntry) -> None:      │
│    452 │   │   """Given a _ConnectionRecord, return it to the :class:`_pool. │
│                                                                              │
│ ╭─────────────────────────── locals ────────────────────────────╮            │
│ │ self = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │            │
│ ╰───────────────────────────────────────────────────────────────╯            │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:1263 in _checkout                                │
│                                                                              │
│   1260 │   │   fairy: Optional[_ConnectionFairy] = None,                     │
│   1261 │   ) -> _ConnectionFairy:                                            │
│   1262 │   │   if not fairy:                                                 │
│ ❱ 1263 │   │   │   fairy = _ConnectionRecord.checkout(pool)                  │
│   1264 │   │   │                                                             │
│   1265 │   │   │   if threadconns is not None:                               │
│   1266 │   │   │   │   threadconns.current = weakref.ref(fairy)              │
│                                                                              │
│ ╭─────────────────────────────── locals ───────────────────────────────╮     │
│ │       fairy = None                                                   │     │
│ │        pool = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │     │
│ │ threadconns = None                                                   │     │
│ ╰──────────────────────────────────────────────────────────────────────╯     │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:712 in checkout                                  │
│                                                                              │
│    709 │   │   if TYPE_CHECKING:                                             │
│    710 │   │   │   rec = cast(_ConnectionRecord, pool._do_get())             │
│    711 │   │   else:                                                         │
│ ❱  712 │   │   │   rec = pool._do_get()                                      │
│    713 │   │                                                                 │
│    714 │   │   try:                                                          │
│    715 │   │   │   dbapi_connection = rec.get_connection()                   │
│                                                                              │
│ ╭─────────────────────────── locals ────────────────────────────╮            │
│ │ pool = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │            │
│ ╰───────────────────────────────────────────────────────────────╯            │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/impl.py:179 in _do_get                                   │
│                                                                              │
│   176 │   │   │   try:                                                       │
│   177 │   │   │   │   return self._create_connection()                       │
│   178 │   │   │   except:                                                    │
│ ❱ 179 │   │   │   │   with util.safe_reraise():                              │
│   180 │   │   │   │   │   self._dec_overflow()                               │
│   181 │   │   │   │   raise                                                  │
│   182 │   │   else:                                                          │
│                                                                              │
│ ╭─────────────────────────────── locals ────────────────────────────────╮    │
│ │         self = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │    │
│ │ use_overflow = True                                                   │    │
│ │         wait = False                                                  │    │
│ ╰───────────────────────────────────────────────────────────────────────╯    │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/util/langhelpers.py:146 in __exit__                           │
│                                                                              │
│    143 │   │   │   exc_type, exc_value, exc_tb = self._exc_info              │
│    144 │   │   │   assert exc_value is not None                              │
│    145 │   │   │   self._exc_info = None  # remove potential circular refere │
│ ❱  146 │   │   │   raise exc_value.with_traceback(exc_tb)                    │
│    147 │   │   else:                                                         │
│    148 │   │   │   self._exc_info = None  # remove potential circular refere │
│    149 │   │   │   assert value is not None                                  │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │    exc_tb = <traceback object at 0x10f8ac8c0>                            │ │
│ │ exc_value = AttributeError("'sqlite3.Connection' object has no attribute │ │
│ │             'enable_load_extension'")                                    │ │
│ │      self = <sqlalchemy.util.langhelpers.safe_reraise object at          │ │
│ │             0x10f8a5750>                                                 │ │
│ │ traceback = None                                                         │ │
│ │     type_ = None                                                         │ │
│ │     value = None                                                         │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/impl.py:177 in _do_get                                   │
│                                                                              │
│   174 │   │                                                                  │
│   175 │   │   if self._inc_overflow():                                       │
│   176 │   │   │   try:                                                       │
│ ❱ 177 │   │   │   │   return self._create_connection()                       │
│   178 │   │   │   except:                                                    │
│   179 │   │   │   │   with util.safe_reraise():                              │
│   180 │   │   │   │   │   self._dec_overflow()                               │
│                                                                              │
│ ╭─────────────────────────────── locals ────────────────────────────────╮    │
│ │         self = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │    │
│ │ use_overflow = True                                                   │    │
│ │         wait = False                                                  │    │
│ ╰───────────────────────────────────────────────────────────────────────╯    │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:390 in _create_connection                        │
│                                                                              │
│    387 │   def _create_connection(self) -> ConnectionPoolEntry:              │
│    388 │   │   """Called by subclasses to create a new ConnectionRecord."""  │
│    389 │   │                                                                 │
│ ❱  390 │   │   return _ConnectionRecord(self)                                │
│    391 │                                                                     │
│    392 │   def _invalidate(                                                  │
│    393 │   │   self,                                                         │
│                                                                              │
│ ╭─────────────────────────── locals ────────────────────────────╮            │
│ │ self = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80> │            │
│ ╰───────────────────────────────────────────────────────────────╯            │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:674 in __init__                                  │
│                                                                              │
│    671 │   │                                                                 │
│    672 │   │   self.__pool = pool                                            │
│    673 │   │   if connect:                                                   │
│ ❱  674 │   │   │   self.__connect()                                          │
│    675 │   │   self.finalize_callback = deque()                              │
│    676 │                                                                     │
│    677 │   dbapi_connection: Optional[DBAPIConnection]                       │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ connect = True                                                           │ │
│ │    pool = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80>         │ │
│ │    self = <sqlalchemy.pool.base._ConnectionRecord object at 0x10e5560e0> │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/pool/base.py:914 in __connect                                 │
│                                                                              │
│    911 │   │   │   # event, so ensure a mutex is used on the first run       │
│    912 │   │   │   pool.dispatch.connect.for_modify(                         │
│    913 │   │   │   │   pool.dispatch                                         │
│ ❱  914 │   │   │   )._exec_w_sync_on_first_run(self.dbapi_connection, self)  │
│    915                                                                       │
│    916                                                                       │
│    917 def _finalize_fairy(                                                  │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ connection = <sqlite3.Connection object at 0x10d622840>                  │ │
│ │       pool = <sqlalchemy.pool.impl.QueuePool object at 0x10f864e80>      │ │
│ │       self = <sqlalchemy.pool.base._ConnectionRecord object at           │ │
│ │              0x10e5560e0>                                                │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/event/attr.py:483 in _exec_w_sync_on_first_run                │
│                                                                              │
│   480 │   │   if not self._exec_w_sync_once:                                 │
│   481 │   │   │   with self._exec_once_mutex:                                │
│   482 │   │   │   │   try:                                                   │
│ ❱ 483 │   │   │   │   │   self(*args, **kw)                                  │
│   484 │   │   │   │   except:                                                │
│   485 │   │   │   │   │   raise                                              │
│   486 │   │   │   │   else:                                                  │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ args = (                                                                 │ │
│ │        │   <sqlite3.Connection object at 0x10d622840>,                   │ │
│ │        │   <sqlalchemy.pool.base._ConnectionRecord object at             │ │
│ │        0x10e5560e0>                                                      │ │
│ │        )                                                                 │ │
│ │   kw = {}                                                                │ │
│ │ self = <sqlalchemy.event.attr._ListenerCollection object at 0x10e5406c0> │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/sqlalchemy/event/attr.py:497 in __call__                                 │
│                                                                              │
│   494 │   │   for fn in self.parent_listeners:                               │
│   495 │   │   │   fn(*args, **kw)                                            │
│   496 │   │   for fn in self.listeners:                                      │
│ ❱ 497 │   │   │   fn(*args, **kw)                                            │
│   498 │                                                                      │
│   499 │   def __contains__(self, item: Any) -> bool:                         │
│   500 │   │   return item in self.parent_listeners or item in self.listeners │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ args = (                                                                 │ │
│ │        │   <sqlite3.Connection object at 0x10d622840>,                   │ │
│ │        │   <sqlalchemy.pool.base._ConnectionRecord object at             │ │
│ │        0x10e5560e0>                                                      │ │
│ │        )                                                                 │ │
│ │   kw = {}                                                                │ │
│ │ self = <sqlalchemy.event.attr._ListenerCollection object at 0x10e5406c0> │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│ /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packa │
│ ges/memos/models.py:173 in load_extension                                    │
│                                                                              │
│   170                                                                        │
│   171                                                                        │
│   172 def load_extension(dbapi_conn, connection_record):                     │
│ ❱ 173 │   dbapi_conn.enable_load_extension(True)                             │
│   174 │                                                                      │
│   175 │   # load simple tokenizer                                            │
│   176 │   current_dir = Path(__file__).parent.resolve()                      │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │ connection_record = <sqlalchemy.pool.base._ConnectionRecord object at    │ │
│ │                     0x10e5560e0>                                         │ │
│ │        dbapi_conn = <sqlite3.Connection object at 0x10d622840>           │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'sqlite3.Connection' object has no attribute  'enable_load_extension'
@arkohut
Copy link
Owner

arkohut commented Nov 22, 2024

Please see this issue: #4

@tianze-hou
Copy link
Author

Thanks for your response.
Apologies for overlooking the previous issue.

@arkohut
Copy link
Owner

arkohut commented Nov 22, 2024

I also update this part in https://github.com/arkohut/pensieve?tab=readme-ov-file#quick-start . You’re welcome to suggest better ways to solve this problem.

@tianze-hou
Copy link
Author

Thanks for your update! I'm still working on this issue.

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

No branches or pull requests

2 participants