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
OperationalError from SQlite that indicates a permissions problem. #2508
Changes from 5 commits
11e3a5a
3fd04ad
bccfcb6
cb2f47d
cf744eb
f7a5844
0492741
e756f98
621427f
19e0958
906bd97
7eaaa99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ | |
from .query import MatchQuery, NullSort, TrueQuery | ||
import six | ||
|
||
class AccessFileError(Exception): | ||
"""UI exception. Commands should throw this in order to display | ||
nonrecoverable errors to the user. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like the description for UserError? Here's an alternative docstring:
|
||
""" | ||
|
||
class FormattedMapping(collections.Mapping): | ||
"""A `dict`-like formatted view of a model. | ||
|
@@ -680,14 +684,17 @@ def mutate(self, statement, subvals=()): | |
"""Execute an SQL statement with substitution values and return | ||
the row ID of the last affected row. | ||
""" | ||
cursor = self.db._connection().execute(statement, subvals) | ||
return cursor.lastrowid | ||
try: | ||
cursor = self.db._connection().execute(statement, subvals) | ||
return cursor.lastrowid | ||
except sqlite3.OperationalError as e: | ||
raise AccessFileError("unable to open database file. It might be a permissions problem") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is where the check for error strings like "attempt to write a readonly database" should occur. (For what it's worth, I did a little experiment—that's the message that appears if I try to access the database after deleting the file from my disk!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, i have to add an if that check if e.args[0] is equals with "attempt to write a readonly database file" and another that checks if e.args[0] is equals with "unable to open database file"? I already tried it and when the message is "unable to open database file" it gives me again the message of UserError. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! Or we can just have one
I don't quite understand what you mean about the UserError… is some other code producing a UserError exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, |
||
|
||
|
||
def script(self, statements): | ||
"""Execute a string containing multiple SQL statements.""" | ||
self.db._connection().executescript(statements) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it seems small, but we need this blank line here for consistency. |
||
class Database(object): | ||
"""A container for Model objects that wraps an SQLite database as | ||
the backend. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "DBAccessError" for clarity?