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

"Links from other tables" broken for columns starting with underscore #1525

Closed
simonw opened this issue Nov 21, 2021 · 3 comments
Closed

"Links from other tables" broken for columns starting with underscore #1525

simonw opened this issue Nov 21, 2021 · 3 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Nov 21, 2021

Same bug as #1506, this time it's this link or the row page:

image

@simonw simonw added the bug label Nov 21, 2021
@simonw
Copy link
Owner Author

simonw commented Nov 21, 2021

Here's the template:

{% for other in foreign_key_tables %}
<li>
<a href="{{ urls.table(database, other.other_table) }}?{{ other.other_column }}={{ ', '.join(primary_key_values) }}">

@simonw
Copy link
Owner Author

simonw commented Nov 21, 2021

https://latest.datasette.io/fixtures/facetable can't quite demonstrate the bug because _neighborhood isn't a foreign key - I should rename city_id to _city_id.

@simonw
Copy link
Owner Author

simonw commented Nov 30, 2021

These two pages now help demonstrate the fix:

I added a new test for these here:

@pytest.mark.parametrize(
"path,expected_text,expected_link",
(
(
"/fixtures/facet_cities/1",
"6 rows from _city_id in facetable",
"/fixtures/facetable?_city_id__exact=1",
),
(
"/fixtures/attraction_characteristic/2",
"3 rows from characteristic_id in roadside_attraction_characteristics",
"/fixtures/roadside_attraction_characteristics?characteristic_id=2",
),
),
)
def test_row_links_from_other_tables(app_client, path, expected_text, expected_link):
response = app_client.get(path)
assert response.status == 200
soup = Soup(response.body, "html.parser")
h2 = soup.find("h2")
assert h2.text == "Links from other tables"
li = h2.findNext("ul").find("li")
text = re.sub(r"\s+", " ", li.text.strip())
assert text == expected_text
link = li.find("a")["href"]
assert link == expected_link

simonw added a commit that referenced this issue Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant