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

Unable to add a SQLite DB #9748

Closed
3 tasks done
hc128168 opened this issue May 6, 2020 · 23 comments
Closed
3 tasks done

Unable to add a SQLite DB #9748

hc128168 opened this issue May 6, 2020 · 23 comments
Labels
!deprecated-label:bug Deprecated label - Use #bug instead

Comments

@hc128168
Copy link

hc128168 commented May 6, 2020

I tried to add a db located at "/home/hc/superset/db/test.db" to superset via "Sources->Databases->Add a new record". I set "sqlite:////home/hc/superset/db/test.db" as SQLAlchemy URI, and hit "Test Connection". And it says, "ERROR: SQLite database cannot be used as a data source for security reasons."

image

  • superset version: 0.36.0
  • python version: 2.7.5 (I have python 3.6 installed as well but not sure which one superset uses)
  • node.js version: not installed as it is not listed as required here nor as optioal
  • npm version: not installed.

Make sure these boxes are checked before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.
@hc128168 hc128168 added the !deprecated-label:bug Deprecated label - Use #bug instead label May 6, 2020
@dpgaspar
Copy link
Member

dpgaspar commented May 6, 2020

Superset is going to drop support for SQLLite, for now you can override this by setting PREVENT_UNSAFE_DB_CONNECTIONS = False on the config

@hc128168
Copy link
Author

hc128168 commented May 6, 2020

@dpgaspar Thanks. It works!

While I looked up the setting, I found the pull request. It seems like it doesn't convert the examples to use another database tho.

@mjsabby
Copy link

mjsabby commented Oct 2, 2020

Is there a reason to drop sqlite?

@hongvvu
Copy link

hongvvu commented Jan 3, 2021

I installed via docker, any instruction on overwrite config.py with docker image?

@mistercrunch
Copy link
Member

Happy to clarify some things here, first the project is dropping support for SQLLite as a metadata database, as it's simply not reliable to support a multi-web servers, multi-workers type of setup which is a fairly basic assumption for an application like Superset in production. As soon as you fire off multiple web workers or thread, you're likely to have issues with SQLLite locks. Given that and the fact that we had a fair amount of SQLLite-specific bugs and regressions (namely around database-migrations and DDL in general), we decided that we would not actively support it.

Now OP was asking about SQLLite as an analytics database, which may/could work in some capacity, assuming the file is mounted / visible from all the processes in the application. This can be done by flipping the feature flag that @dpgaspar pointed to, but may introduce security risk, where a user may be able to access some other SQLLite database living on the local filesystem (other applications or systems on the local machine could use a SQLLite database in a deterministic location, and a hacker could obtain access to it and potentially modify it if the OS rules allow the superset OS user to do this). There may be other Security-related issues as well that I'm not aware of here as well.

@doricardo-zz
Copy link

I installed via docker, any instruction on overwrite config.py with docker image?

Hi, Did you find how to do it?

@hongvvu
Copy link

hongvvu commented Feb 21, 2021

I installed via docker, any instruction on overwrite config.py with docker image?

Hi, Did you find how to do it?

Wrote a blog post about it, and managed to overwrite config.py in my docker image.
https://abouthongwuxyz.typlog.io/2021/superset-docker-local-db-sqlite-configuration-dcf6876e

@harshhacks
Copy link

Hi, facing the same error in Windows but editing the config.py and including CSV doesn't remove the error.

Using Python 3.8 and Windows 10 for context and a SQLite database.
Changed the config file to have:
SQLALCHEMY_DATABASE_URI = 'sqlite:///C:\Users\harsh\.superset\superset.db'
PREVENT_UNSAFE_DB_CONNECTIONS = False

Does anyone have an idea of what could be causing this?

@jaanli
Copy link

jaanli commented Sep 8, 2021

It would be helpful to support sqlite databases. I work at a hospital and it would be very helpful to analyze health records data with sqlite rather than hosting my own mysql database.

Thank you!

Pipboyguy pushed a commit to Pipboyguy/superset that referenced this issue Sep 21, 2021
- superset_config.py flag
- Add parent git repo treasury SQLITEDB

See issue apache#9748
@av-2024
Copy link

av-2024 commented Feb 14, 2022

Well I was pretty excited about superset and spent a lot of time setting it up for a small scale self-hosted solution. Now I'm rather disappointed. Do you know how many of your users use SQLite?

@kopytjuk
Copy link

kopytjuk commented May 8, 2022

An ugly (but working) hack for those who want to alter the Docker image:

FROM apache/superset

# Switching to root to install the required packages
USER root

# allow sqlite
RUN echo "PREVENT_UNSAFE_DB_CONNECTIONS = False" >> /app/superset/config.py

# Switching back to using the `superset` user
USER superset

This only works, because config.py defines the variables on the global level, so the last variable definition wins :)

@jaanli
Copy link

jaanli commented May 9, 2022

This is so helpful! Thank you @kopytjuk

Can we please reopen this issue? Desperately need sqlite because we are a small nonprofit and cannot use anything more.

@FoXTecktoniK
Copy link

FoXTecktoniK commented May 11, 2022

  1. open superset/docker/pythonpath_dev/superset_config.py

  2. add PREVENT_UNSAFE_DB_CONNECTIONS = False somewhere

  3. start a docker container
    The setting is applied, but the database is not yet there

  4. open docker-compose.yml (or docker-compose-non-dev.yml)

  5. find lines

  # /app/pythonpath_docker will be appended to the PYTHONPATH in the final container
  - ./docker:/app/docker
  - superset_home:/app/superset_home

add line at the bottom - ./coins.db:/app/coins.db, where ./local.db - file in superset folder
use connection string sqlite:///local.db in superset

@bobhenkel
Copy link

The excellent news is sqlite connection is still working as of today's date once I added PREVENT_UNSAFE_DB_CONNECTIONS = False. Please keep sqlite as an option and document it as non-production use only. Many use cases where you have a sqlite.db file full of data and want to impress folks by connecting that data to superset.

@neiz
Copy link

neiz commented Feb 23, 2023

@mistercrunch my intent is not to reopen this issue, but more to use this issue for context -

It's a bit frustrating to use the official dockerhub image only to have the examples not work/load and having to stumble across the fact that SQLite was removed. Might make sense to remove the examples, or change them such that they work out of the box

@cserb
Copy link

cserb commented Mar 6, 2023

Did something change again? I can't make it work with PREVENT_UNSAFE_DB_CONNECTIONS = False

I agree with @neiz here. It's just frustrating that it is advertised but than once you try to connect it's not allowed. I honestly also don't get this silly security concern if I want to run it locally...

@ninja-tech
Copy link

https://abouthongwuxyz.typlog.io/2021/superset-docker-local-db-sqlite-configuration-dcf6876e

this link is not working

@harabat
Copy link

harabat commented Nov 30, 2023

Still trying to make SQLite work on the official Docker image, if anyone has a solution.

I managed to remove the warning by mounting a modified config.py with the PREVENT_UNSAFE_DB_CONNECTIONS = False setting:

curl --remote-name https://raw.githubusercontent.com/apache/superset/master/superset/config.py  # download config.py file
vi config.py  # add the line ~PREVENT_UNSAFE_DB_CONNECTIONS = False~ inside the file, before the line containing "WARNING:  STOP EDITING  HERE"
docker run -d -p 8080:8088
            -e "SUPERSET_SECRET_KEY=your_secret_key_here"
            -v /path/to/modified/config.py:/app/superset/config.py  # mount local config.py
            --name superset apache/superset
docker exec -it superset superset fab create-admin \
              --username admin \
              --firstname Superset \
              --lastname Admin \
              --email admin@superset.com \
              --password admin
docker exec -it superset superset db upgrade
docker exec -it superset superset init

The above removes the SQLite security warning, but trying to connect to the db triggers a sqlite3.OperationalError when loading a SQLite db.

superset_sqlite

I tried to connect with sqlite:///path/to/my/local.db and mounting the db into the /app/ directory and connecting with sqlite:///local.db, but keep getting that error.

@weeebdev
Copy link

weeebdev commented Jan 2, 2024

Still trying to make SQLite work on the official Docker image, if anyone has a solution.

I managed to remove the warning by mounting a modified config.py with the PREVENT_UNSAFE_DB_CONNECTIONS = False setting:

curl --remote-name https://raw.githubusercontent.com/apache/superset/master/superset/config.py  # download config.py file
vi config.py  # add the line ~PREVENT_UNSAFE_DB_CONNECTIONS = False~ inside the file, before the line containing "WARNING:  STOP EDITING  HERE"
docker run -d -p 8080:8088
            -e "SUPERSET_SECRET_KEY=your_secret_key_here"
            -v /path/to/modified/config.py:/app/superset/config.py  # mount local config.py
            --name superset apache/superset
docker exec -it superset superset fab create-admin \
              --username admin \
              --firstname Superset \
              --lastname Admin \
              --email admin@superset.com \
              --password admin
docker exec -it superset superset db upgrade
docker exec -it superset superset init

The above removes the SQLite security warning, but trying to connect to the db triggers a sqlite3.OperationalError when loading a SQLite db.

superset_sqlite

I tried to connect with sqlite:///path/to/my/local.db and mounting the db into the /app/ directory and connecting with sqlite:///local.db, but keep getting that error.

Any news?

@gramakri
Copy link

gramakri commented Apr 6, 2024

@harabat did you figure out that error? I get the same error.

Apr 06 11:49:38 2024-04-06 09:49:38,164:WARNING:superset.views.base:SupersetErrorsException <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - Traceback (most recent call last): <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/commands/database/test_connection.py", line 161, in run <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - raise DBAPIError(ex_str or None, None, None) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - sqlalchemy.exc.DBAPIError: (builtins.NoneType) None <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - [SQL: (sqlite3.OperationalError) unable to open database file <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - (Background on this error at: https://sqlalche.me/e/14/e3q8)] <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - (Background on this error at: https://sqlalche.me/e/14/dbapi) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 -
Apr 06 11:49:38 The above exception was the direct cause of the following exception: <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - Traceback (most recent call last): <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/flask/app.py", line 1823, in full_dispatch_request <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - rv = self.dispatch_request() <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/flask/app.py", line 1799, in dispatch_request <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/flask_appbuilder/security/decorators.py", line 95, in wraps <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - return f(self, *args, **kwargs) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/views/base_api.py", line 127, in wraps <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - raise ex <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/views/base_api.py", line 121, in wraps <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - duration, response = time_function(f, self, *args, **kwargs) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/utils/core.py", line 1463, in time_function <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - response = func(*args, **kwargs) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/utils/log.py", line 255, in wrapper <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - value = f(*args, **kwargs) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/views/base_api.py", line 93, in wraps <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - return f(self, *args, **kwargs) <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/databases/api.py", line 919, in test_connection <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - TestConnectionDatabaseCommand(item).run() <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - File "/app/code/superset/superset/commands/database/test_connection.py", line 190, in run <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - raise SupersetErrorsException(errors) from ex <30>1 2024-04-06T09:49:38Z my 01b635dd-19eb-4294-ace3-54c0321ce5a2 1028 01b635dd-19eb-4294-ace3-54c0321ce5a2 - superset.exceptions.SupersetErrorsException: [SupersetError(message='(builtins.NoneType) None\n[SQL: (sqlite3.OperationalError) unable to open database file\n(Background on this error at: https://sqlalche.me/e/14/e3q8)]\n(Background on this error at: https://sqlalche.me/e/14/dbapi)', error_type=<SupersetErrorType.GENERIC_DB_ENGINE_ERROR: 'GENERIC_DB_ENGINE_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra={'engine_name': 'SQLite', 'issue_codes': [{'code': 1002, 'message': 'Issue 1002 - The database returned an unexpected error.'}]})]

@harabat
Copy link

harabat commented Apr 23, 2024

@gramakri unfortunately not, had to go with other tools instead.

@pjaol
Copy link

pjaol commented May 7, 2024

Managed to get it to work, am using docker compose for ease of use

docker-compose.yaml

version: '3'
services:
  superset:
    image: apache/superset
    ports:
      - 8088:8088
    volumes:
      - /home/pjaol/flows/data:/var/data # where my data resides
      - superset_db:/app/superset_home # persist config across restarts
    environment:
      - SUPERSET_CONFIG_PATH=/var/data/superset_config.py
      - SUPERSET_SECRET_KEY=something_random

volumes:
  superset_db:

And

superset_config.py

# Superset configuration file
PREVENT_UNSAFE_DB_CONNECTIONS=False

When using an absolute path ensure you are using 4 forward slashes sqlite:////var/data/data.db in my case
It's using apache/superset:latest image

@sammigachuhi
Copy link

sammigachuhi commented May 28, 2024

Hello, I realized there is a way you can upload the sqlite to superset but the issue is that in the SQL Lab you cannot see the tables. Use the following format: sqlite:///C:\\Users\\user\\Downloads\\your_db.db?check_same_thread=false. Yes, just use the two backslashes in between the folder paths not forward (/) because the latter will fail. The Sqlite database will be loaded and will be visible. However, the tables in the sqlite db can't be read in the SQL Lab despite being existent.

Would really appreciate if someone found a way to make the tables in the database readable or visible in the datasets menu, otherwise we are still so close but still so far.

Prior to this ensure you have turned PREVENT_UNSAFE_DB_CONNECTIONS=false in the config.py before heading to this final step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
!deprecated-label:bug Deprecated label - Use #bug instead
Projects
None yet
Development

No branches or pull requests