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

Parts of YAML file do not work when db name is "off" #1798

Closed
CharlesNepote opened this issue Sep 1, 2022 · 4 comments
Closed

Parts of YAML file do not work when db name is "off" #1798

CharlesNepote opened this issue Sep 1, 2022 · 4 comments

Comments

@CharlesNepote
Copy link

I guess this issue is not very important and probably rare.

To reproduce:

  • create and populate a db named off.db
  • in the yaml file, add any kind of information below databases:\n off:
  • the data are not taken into account (because "off" is interpreted as "false")

YAML file:

title: Some title
description_html: |-
  <p>This is an experiment.</p>
databases:
  off:
    tables:
      products_from_owners:
        title: products_from_owners*
        description_html: |-
          <p>Description</p>

The result for http://xxxx.xxx/-/metadata gives:

{
    "title": "Some title",
    "description_html": "<p>This is an experiment.</p>",
    "databases": {
        "false": {
            "tables": {
                "products_from_owners": {
                    "title": "products_from_owners*",
                    "description_html": "<p>Description</p>"
                }
            }
        }
    }
}

=> see the "false" instead of "off".

@simonw
Copy link
Owner

simonw commented Sep 1, 2022

Oh that's a classic YAML problem, I hadn't realized it would affect Datasette like this!

You should be able to fix it by quoting the off key like this:

title: Some title
description_html: |-
  <p>This is an experiment.</p>
databases:
  "off":
    tables:
      products_from_owners:
        title: products_from_owners*
        description_html: |-
          <p>Description</p>

@simonw simonw closed this as completed Sep 1, 2022
@simonw
Copy link
Owner

simonw commented Sep 2, 2022

There's a thread about this here, but it doesn't have any workaround that look to me like they would be worth applying: https://stackoverflow.com/questions/36463531/pyyaml-automatically-converting-certain-keys-to-boolean-values

@simonw
Copy link
Owner

simonw commented Sep 2, 2022

It's a nasty gotcha though. I'm inclined to add validation to Datasette that fails to start the server with an error if you attempt to start it with metadata that accidentally has a boolean where a database name is expected.

@simonw simonw transferred this issue from simonw/datasette.io Sep 2, 2022
@simonw
Copy link
Owner

simonw commented Sep 2, 2022

Here's a very old issue that suggests validating metadata:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants