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

Web2py filesystem issues #697

Merged
merged 5 commits into from
Aug 14, 2022
Merged

Web2py filesystem issues #697

merged 5 commits into from
Aug 14, 2022

Conversation

macneiln
Copy link
Contributor

Logic to resolve #696.

macneiln and others added 5 commits August 10, 2022 18:33
Binary field type in PostgreSQL is type "BYTEA" not BLOB.
The filename is being inadvertently encoded which results in each subsequent lookup being unable to locate the appropriate path and results in a web2py_filesystem duplicate primary key error when starting py4web.
@@ -488,7 +488,8 @@ def try_create_web2py_filesystem(db):
raise NotImplementedError(
"DatabaseStoredFile only supported by mysql, potresql, sqlite"
)
sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content BLOB, PRIMARY KEY(path));"
blobType = "BYTEA" if db._adapter.dbengine == "postgres" else "BLOB"
sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content %(blobType)s, PRIMARY KEY(path));" % {"blobType": blobType}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is problematic. It will may break apps of current users if the table already exists. Can you explain why it is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "BLOB" field type doesn't exist in PostgreSQL, it's type "BYTEA", so currently it just errors attempting to create the web2py_filesystem table with "BLOB type does not exist" since it's not available in PostgreSQL.
https://www.postgresql.org/docs/current/datatype-binary.html

@@ -315,7 +315,11 @@ def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None):
query = "CREATE TABLE %s(\n %s\n)%s" % (table_rname, fields, other)

uri = self.adapter.uri
if uri.startswith("sqlite:///") or uri.startswith("spatialite:///"):
if isinstance(self, InDBMigrator):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@mdipierro mdipierro merged commit 4630db3 into web2py:master Aug 14, 2022
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

Successfully merging this pull request may close these issues.

web2py_filesystem Updates/Corrections
2 participants