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

SQLite Error: DatabaseError: database disk image is malformed #327

Closed
michaelweinold opened this issue Apr 24, 2023 · 1 comment
Closed

Comments

@michaelweinold
Copy link
Contributor

michaelweinold commented Apr 24, 2023

peewee was recently added (#322), but it seems that an error with sqlite (added by @DerThorsten last year) is preventing us from running this small test script:

from peewee import *

# Define a database object
db = SqliteDatabase('my_database.db')

# Define a model class
class Person(Model):
    name = CharField()
    age = IntegerField()

    class Meta:
        database = db

# Create the table in the database
db.connect()
db.create_tables([Person])
person1 = Person(name='Alice', age=25)
person1.save()

This returns:

DatabaseError: database disk image is malformed
Full Error Message
---------------------------------------------------------------------------
DatabaseError                             Traceback (most recent call last)
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
 3235             cursor = self.cursor()
-> 3236             cursor.execute(sql, params or ())
 3237         return cursor

DatabaseError: database disk image is malformed

During handling of the above exception, another exception occurred:

DatabaseError                             Traceback (most recent call last)
/tmp/xpython_42/2390659374.py in <cell line: 2>()
    1 person1 = Person(name='Alice', age=25)
----> 2 person1.save()

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in save(self, force_insert, only)
 6745             rows = self.update(**field_dict).where(self._pk_expr()).execute()
 6746         elif pk_field is not None:
-> 6747             pk = self.insert(**field_dict).execute()
 6748             if pk is not None and (self._meta.auto_increment or
 6749                                    pk_value is None):

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in inner(self, database, *args, **kwargs)
 1960             raise InterfaceError('Query must be bound to a database in order '
 1961                                  'to call "%s".' % method.__name__)
-> 1962         return method(self, database, *args, **kwargs)
 1963     return inner
 1964 

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute(self, database)
 2031     @database_required
 2032     def execute(self, database):
-> 2033         return self._execute(database)
 2034 
 2035     def _execute(self, database):

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in _execute(self, database)
 2836             self._returning = (self.table._primary_key,)
 2837         try:
-> 2838             return super(Insert, self)._execute(database)
 2839         except self.DefaultValuesException:
 2840             pass

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in _execute(self, database)
 2549             cursor = self.execute_returning(database)
 2550         else:
-> 2551             cursor = database.execute(self)
 2552         return self.handle_result(database, cursor)
 2553 

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute(self, query, commit, **context_options)
 3242         ctx = self.get_sql_context(**context_options)
 3243         sql, params = ctx.sql(query).query()
-> 3244         return self.execute_sql(sql, params)
 3245 
 3246     def get_context_options(self):

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
 3232             __deprecated__('"commit" has been deprecated and is a no-op.')
 3233         logger.debug((sql, params))
-> 3234         with __exception_wrapper__:
 3235             cursor = self.cursor()
 3236             cursor.execute(sql, params or ())

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in __exit__(self, exc_type, exc_value, traceback)
 3008             new_type = self.exceptions[exc_type.__name__]
 3009             exc_args = exc_value.args
-> 3010             reraise(new_type, new_type(exc_value, *exc_args), traceback)
 3011 
 3012 

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in reraise(tp, value, tb)
  190     def reraise(tp, value, tb=None):
  191         if value.__traceback__ is not tb:
--> 192             raise value.with_traceback(tb)
  193         raise value
  194 

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
 3234         with __exception_wrapper__:
 3235             cursor = self.cursor()
-> 3236             cursor.execute(sql, params or ())
 3237         return cursor
 3238 

DatabaseError: database disk image is malformed

To reproduce the error, access my JupyterLite Hub and open peewee_test.ipynb at https://michaelweinold.github.io/hub/

According to peewee author Charles Leifer

"the error is not coming from peewee but seems related to however you're abstracting the file-system for use by sqlite. The error is coming from sqlite and seems to indicate some problem with the file."

Could you someone have a look? I know too little about the file system underlying JupyterLite to make any meaningful contributions at this point.

@michaelweinold
Copy link
Contributor Author

...I suppose this issue belongs to the JupyterLite repo rather than here. Moving it there

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

1 participant