-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add slug
field to Organization
#6395
Conversation
This causes the backend checks to fail: This is non-null very deliberately, by necessity, on relatively small tables – so I don't think we're in danger here. At the same time I don't know how to disable this check for migration operations that use SQL generated by Django (as opposed to |
slug
fields to Organization
and Team
slug
fields to Organization
Actually I scaled this down to only add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! I would only consider the migration question as potentially blocker
posthog/models/utils.py
Outdated
slugified_name = slugify(kwargs["name"])[:MAX_SLUG_LENGTH] if "name" in kwargs else default_slug | ||
for i in range(10): | ||
# This retry loop handles possible duplicates by appending `-\d` to the slug in case of an IntegrityError | ||
slugified_name_i = slugified_name[: MAX_SLUG_LENGTH - 2] if i == 0 else f"{slugified_name}-{i}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a better approach would be to generate a random 3 or 4 integer number and only try like 5 times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do something really similar in ee/clickhouse/materialized_columns/columns.py#materialized_column_name and I suggest that approach instead.
Basically if there's a conflict we generate a n-letter random ascii-letter suffix and append that. :)
Worth unifying the two approaches at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I unified the suffix logic using the materialized_column_name
approach – more unique = better. Used the same in the migration.
Co-authored-by: Paolo D'Amico <[email protected]>
slug
fields to Organization
slug
field to Organization
If you change the organisation's name, and change its slug, all existing links/bookmarks for users will now be invalidated. Do we want to
? |
I think this will be rare enough that we can put this off a bit, but in the end I think it'll be best for the slug to only be manually changeable in org settings. Maybe with a nicer settings layout, though that's not a prerequisite, just a very-nice-to-have. As for past slugs, would love some automagicness with redirecting from them, but at org level I'd prefer to free unused slugs up instead. |
Changes
Slugs. We all love these slimy creatures, and today I'm honored to introduce them into our backend.
How so? Well, we want to point to organizations and projects with URLs instead of relying on
User
fields. We could just use IDs there… but they're completely not user-friendly. Obviously they are impenetrable for humans, but additionally:The solution that seems much better for humans is slug IDs. This PR adds them (inferring their values from entity display names) for orgs and projects, so that soon we can have URLs like this
app.posthog.com/orgs/hogflix/projects/foobar-test-123
instead of
app.posthog.com/orgs/12add3aa-5e5c-47dc-8bad-e39f83d45505/projects/666
.In the future slugs may also be fully customizable, but that's not important now, and the obstacle I encountered while trying that out is… our settings pages. They've been growing ad hoc with no layout system, and that just shows – it's getting awkward adding more options, as there's no structure to it all, and the number of Save buttons rises. I think it'll be worth thinking about a long-term system before adding more granular settings like this.
How did you test this code?
I ran the migration, including a case of duplicated names.
Also manually tried creating and renaming orgs/projects.
And there are some new tests including edge cases.