You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "xavier-GitHub76 (via GitHub)" <gi...@apache.org> on 2024/05/24 09:51:21 UTC
[I] Can't import dashbaords with CLI [superset]
xavier-GitHub76 opened a new issue, #28692:
URL: https://github.com/apache/superset/issues/28692
### Bug description
Hello,
I try to export/import dashboard with cli but I have an error "superset.commands.exceptions.CommandInvalidError: Error importing dashboard"
### How to reproduce the bug
I export my dashboards with CLI :

I delete all elements on my superset




I try import with cli
superset import-dashboards -p myDashboards.zip -u xavier

I try also after a creation of database connexion :


Best regards
### Screenshots/recordings
_No response_
### Superset version
master / latest-dev
### Python version
3.9
### Node version
16
### Browser
Chrome
### Additional context
_No response_
### Checklist
- [ ] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "Adriellevy (via GitHub)" <gi...@apache.org>.
Adriellevy commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2604619039
> [@maximStafeevAtAllscripts](https://github.com/maximStafeevAtAllscripts) What worked for me:
>
> 1. Unzip the file
> 2. Go to dashboards directory
> 3. Password is represented as XXXXXXXXX there
> 4. I replaced it with actual password and compressed again.
> 5. Upload it using CLI or GUI. Both works and doesn't ask for password prompt.
This stil works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "xavier-GitHub76 (via GitHub)" <gi...@apache.org>.
xavier-GitHub76 commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-3018285634
I redo a test with 5.0.0rc4-dev : export / import are OK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2129124821
<!-- Answer -->
To resolve the `superset.commands.exceptions.CommandInvalidError: Error importing dashboard` issue when trying to import dashboards using the CLI in Apache Superset, follow these steps:
1. **Check User Permissions**:
Ensure the user has the necessary permissions to create or overwrite dashboards. This is checked by `security_manager.can_access("can_write", "Dashboard")`.
2. **Validate Configuration**:
Ensure the dashboard configuration (`config` dictionary) is correctly formatted and includes all necessary fields. Pay special attention to the `uuid`, `position`, and `metadata` fields.
3. **Handle UUIDs and IDs**:
Ensure that the UUIDs for charts and datasets are correctly mapped and updated in the configuration. The `update_id_refs` function helps in updating these references.
4. **Remove Deprecated Fields**:
Remove any deprecated fields from the configuration, such as `show_native_filters` in the `metadata`.
Additionally, ensure that the CLI command for importing dashboards is correctly used. Here is an example of how to use the `import_dashboards` command from `superset/cli/importexport.py`:
```python
@click.command()
@with_appcontext
@click.option(
"--path",
"-p",
required=True,
help="Path to a single ZIP file",
)
@click.option(
"--username",
"-u",
required=True,
help="Specify the user name to assign dashboards to",
)
def import_dashboards(path: str, username: Optional[str]) -> None:
"""Import dashboards from ZIP file"""
from superset.commands.dashboard.importers.dispatcher import ImportDashboardsCommand
from superset.commands.importers.v1.utils import get_contents_from_bundle
if username is not None:
g.user = security_manager.find_user(username=username)
if is_zipfile(path):
with ZipFile(path) as bundle:
contents = get_contents_from_bundle(bundle)
else:
with open(path) as file:
contents = {path: file.read()}
try:
ImportDashboardsCommand(contents, overwrite=True).run()
except Exception: # pylint: disable=broad-except
logger.exception(
"There was an error when importing the dashboards(s), please check "
"the exception traceback in the log"
)
sys.exit(1)
```
By following these steps and ensuring the configuration and permissions are correctly handled, you should be able to resolve the `CommandInvalidError` when importing dashboards using the CLI in Apache Superset <sup>[[1]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/importers/v1/utils.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/cli/importexport.py)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/importers/v1/__init__.py)</sup>.
<!-- Dosu Comment Footer -->
<details>
<summary>
#### Details
</summary>
**About Dosu**
This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
</details>
*To continue the conversation, mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "muralikrishnankh (via GitHub)" <gi...@apache.org>.
muralikrishnankh commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2337761581
@maximStafeevAtAllscripts What worked for me:
1. Unzip the file
2. Go to dashboards directory
3. Password is represented as XXXXXXXXX there
4. I replaced it with actual password and compressed again.
5. Upload it using CLI or GUI. Both works and doesn't ask for password prompt.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2337766712
<!-- Answer -->
I found some similar issues and discussions that might help you resolve the "superset.commands.exceptions.CommandInvalidError: Error importing dashboard" error when using the CLI to import dashboards in Apache Superset:
1. **Similar Discussions**:
- [superset import-dashboards KeyError: 'ZIPPED_FILE_MAX_SIZE'](https://github.com/apache/superset/discussions/25742) <sup>[[1]](https://github.com/apache/superset/discussions/25742)</sup>
- [Dashboard Import Error: An error occurred while importing dashboard: Error importing dashboard Please re-export your file and try importing again superset](https://github.com/apache/superset/discussions/25987) <sup>[[2]](https://github.com/apache/superset/discussions/25987)</sup>
2. **Closed Issues**:
- [Importing dashboard error](https://github.com/apache/superset/issues/27284): The suggested solution is to ensure the folder structure of the zip file is correct. The structure should look like this:
```
Root
|
-> dataset_export_20240308T102914
|
-> Databases
-> Datasets
```
<sup>[[3]](https://github.com/apache/superset/issues/27284)</sup>
- [export, import dashboard error ..](https://github.com/apache/superset/issues/21898): The suggested solution is to manually create the database connection first, then the import wizard will ask for the database password <sup>[[4]](https://github.com/apache/superset/issues/21898)</sup>.
- [Dashboard import asking for password database failed](https://github.com/apache/superset/issues/20288): The suggested solution is to use the API for importing dashboards instead of the CLI. Here is a sample script:
```python
import requests
new_zip_file = 'path/to/dashboard_export.zip'
username = 'admin'
password = 'admin'
base_url = 'http://localhost:8088'
while True:
try:
response = requests.get(base_url, timeout=10)
response.raise_for_status()
break
except Exception:
pass
login_url = f"{base_url}/login/"
session = requests.Session()
payload = {}
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'en-US,en;q=0.9'
}
response = session.request("GET", login_url, headers=headers, data=payload)
csrf_token = response.text.split('<input id="csrf_token" name="csrf_token" type="hidden" value="')[1].split('">')[0]
# perform login
payload = f'csrf_token={csrf_token}&username={username}&password={password}'
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded'}
session.request("POST", login_url, headers=headers, data=payload, allow_redirects=False)
cookie = session.cookies.get_dict().get('session')
print(session.cookies.get_dict())
# Import dashboards
import_dashboard_url = f"{base_url}/api/v1/dashboard/import/"
with open(new_zip_file, 'rb') as f:
payload = {
'passwords': '{"databases/replaceWithYourDatabase.yaml":"databasePassword"}',
'overwrite': 'true'
}
files = [
('formData', ('dashboards.zip', f, 'application/zip'))
]
headers = {
'Accept': 'application/json',
'Cookie': f'session={cookie}',
'X-CSRFToken': csrf_token
}
response = requests.request("POST", import_dashboard_url, headers=headers, data=payload, files=files)
print(response.text)
```
<sup>[[5]](https://github.com/apache/superset/issues/20288)</sup>
Additionally, ensure that the user running the import command has the necessary permissions to either overwrite an existing dashboard or create a new one. The `ImportDashboardsCommand` class handles the import process and checks for these permissions <sup>[[6]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/importers/v1/utils.py)</sup><sup>[[7]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/importers/v0.py)</sup><sup>[[8]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/importers/v1/__init__.py)</sup>.
If the user does not have the necessary permissions, you can either grant the required permissions or run the import command with a user who has the appropriate permissions. Also, make sure that the JSON file being imported is valid and contains the necessary data for the import process.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2338996022
Pinging @betodealmeida in case they have any insight here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "maximStafeevAtAllscripts (via GitHub)" <gi...@apache.org>.
maximStafeevAtAllscripts commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2209216260
If I import dashboard via GUI than import_dashboard from CLI successfully updates the dashboard.
I'm also wondering where should I place the password for the database when importing via CLI? Superset prompts you for it when importing through the GUI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "maximStafeevAtAllscripts (via GitHub)" <gi...@apache.org>.
maximStafeevAtAllscripts commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2209197802
Yes, I have the same problem. Neither export nor import works on 4.0.1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "anhvh1408 (via GitHub)" <gi...@apache.org>.
anhvh1408 commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2133812467
I have same issue as you too, in my cases:
- I have dashboards in json file first (exported from superset 2.0.0)
- import json file to superset 3.1.3-dev -> work, dashboard shown perfectly
- then I export these dashboards to zip and import again (both in superset 3.1.3-dev) -> some work, some throw errors same as yours
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "xavier-GitHub76 (via GitHub)" <gi...@apache.org>.
xavier-GitHub76 commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2134840393
Hello,
my zip file is correct : the zip file (created from CLI) is imported with success from gui
I have just the error when I import the zip file from CLI
I have try again on superset 4.0.0, I have the same behavior
Best regards
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Can't import dashbaords with CLI [superset]
Posted by "anhvh1408 (via GitHub)" <gi...@apache.org>.
anhvh1408 commented on issue #28692:
URL: https://github.com/apache/superset/issues/28692#issuecomment-2134335535
Okay, please follow this https://github.com/apache/superset/issues/26130 to debug your zip file and yaml file to see any arguments have errors
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org