Giter VIP home page Giter VIP logo

Comments (3)

brandonrobertz avatar brandonrobertz commented on September 22, 2024

Yeah we're seeing this too only on specific routes. The one that's breaker for us is the CSV export URL. Potentially related to #1619

I'm gonna work on this issue next week because it's a show stopper for us using Datasette in prod.

from datasette.

brandonrobertz avatar brandonrobertz commented on September 22, 2024

I traced the problem down to two areas in the Datasette code and am working on a fix.

The first is in datasette/url_builder.py inside the Urls.path method:

if path.startswith("/"):
path = path[1:]
path = self.ds.setting("base_url") + path

In the last line, sometimes the path here already has the base_url prepended and the path is not an instance of PrefixedUrlString so the base_url gets added twice.

The second issue is datasette/app.py inside the absolute_url method:

url = urllib.parse.urljoin(request.url, path)

The path sometimes comes in here with a base_url prepended but without a leading slash and the request.url also has the base_url at the end of the URL so this results in a double prepend of the base_url.

I'm currently adding some tests, but it's very unclear what the intended functionality was with these methods. So far I have test cases on the datasette.urls.path method like so:

@pytest.mark.parametrize(
    "base_url,path,format,expected",
    [
        ("/", "/", None, "/"),
        (None, "/", None, "/"),
        (None, "", None, ""),
        ("/prefix/", "/prefix/table/1", None, "/prefix/table/1"),
        ("/prefix/", "prefix/table/1", None, "prefix/table/1"),
        ("/prefix/", "/table/1", None, "/prefix/table/1"),
        ("/prefix/", "/table/1", "json", "/prefix/table/1.json"),
        ("/prefix/", "-/static/app.css", None, "/prefix/-/static/app.css"),
        (None, "table/1", None, "table/1"),
        (None, "table/1", "csv", "table/1.csv"),
        (None, "-/static/app.css", None, "-/static/app.css"),
    ],
)
def test_url_path_construction(ds, base_url, path, format, expected):
    ds._settings["base_url"] = base_url
    actual = ds.urls.path(path, format=format)
    assert actual == expected
    assert isinstance(actual, PrefixedUrlString)

Working on profiling the app to see how it seems to be expecting to handle URLs and will add more tests onto path as well as absolute_url.

from datasette.

brandonrobertz avatar brandonrobertz commented on September 22, 2024

Tracking code here: https://github.com/brandonrobertz/datasette/tree/fix-repeated-base_url

from datasette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.