-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Use dictionaries instead of tuples for linkifiers. #17596
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
Use dictionaries instead of tuples for linkifiers. #17596
Conversation
|
||
# This is a legacy event type to ensure backwards compatibility | ||
# for old clients. Newer clients should handle only the | ||
# "realm_linkifiers" event above. |
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.
Does realm_filter_type
get used any more after your changes? We should keep it, since we still need to support old clients. But we probably won't test it in test_events
. Instead, we'll probably want you to introduce some test in test_linkifiers.py
or similar that simulates an old client connecting to us, and we'll want to make sure the payload adheres to this schema. I'm not exactly sure where that test should go, actually, and there might be an existing test that we just modify.
076a117
to
28ba55e
Compare
This looks very clean and thorough! One quick question is where do we test with the old schema (i.e. edit - I see it now...makes sense that it's still in the event test since we're still send the event |
28ba55e
to
be9414d
Compare
The last push was just a change to the commit body so as to mention that we send both the old and the new event types. |
271619a
to
ed4c245
Compare
pattern = options["pattern"] | ||
if not pattern: | ||
self.print_help("./manage.py", "realm_filters") | ||
self.print_help("./manage.py", "realm_linkifier") |
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.
I think there's probably a prep commit you could do to make this access its own command name via sys.args[1] or something rather than hardcoding? Not sure how easy this is with Django's management command system, but that'd be a good sweep to do.
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.
I added a prep commit which does that sweep, and yet another one before it as a small correction 😄
global per_request_realm_filters_cache | ||
per_request_realm_filters_cache = {} | ||
global per_request_linkifiers_cache | ||
per_request_linkifiers_cache = {} |
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.
Definitely don't try to do this change in this commit, but I think we can actually rename RealmFilter
to Linkifier
in models.py
with a small Django configuration option to set the database table name to still be zerver_realmfilter
.
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.
I haven't put any of the following in this PR, but just writing my findings here...
There's a db_table
meta property which we can specify for the table name. So a diff like this-
-class RealmFilter(models.Model):
+class Linkifier(models.Model):
"""Realm-specific regular expressions to automatically linkify certain
strings inside the Markdown processor. See "Custom filters" in the settings UI.
"""
@@ -869,6 +869,7 @@ class RealmFilter(models.Model):
url_format_string: str = models.TextField(validators=[URLValidator(), filter_format_validator])
class Meta:
+ db_table = "zerver_realmfilter"
unique_together = ("realm", "pattern")
Results in a migration like so-
operations = [
migrations.RenameModel(
old_name='RealmFilter',
new_name='Linkifier',
),
migrations.AlterModelTable(
name='linkifier',
table='zerver_realmfilter',
),
]
Is that what you have in mind?
Another question I have is, why not change the database table name? I tried running migrations both ways -- specifying the db_name
to be the old zerver_realmfilter
and not specifying it (so that it defaults to zerver_linkifier
). There seems to be no data loss in either case.
|
||
data["pattern"] = r"lp:(?P<id>[0-9]+)" | ||
data["url_format_string"] = "https://realm.com/my_realm_filter/?sort=reverse&value=%(id)s" | ||
data["url_format_string"] = "https://realm.com/my_linkifier/?sort=reverse&value=%(id)s" |
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.
Definitely don't this in the current commit, but ideally we should change these to use the IETF standard example.com
as the main domain. (Maybe bugs.example.com/?sort...
for this launchpad example, and similar for the ones that are Jira or the like.
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.
I removed these specific changes from the commit. Many similar URL strings are also there in markdown_test_cases.json
. Do those need to be changed as well?
I posted a hopefully complete batch of comments on the 2nd commit (the first was merged in #17625). Thanks @abhijeetbodas2001, I'm very excited about this. |
44682b2
to
9bf7954
Compare
@timabbott Thanks for the review! I addressed most of your comments, except the last couple ones. I didn't understand what you mean by "don't try to do this in this commit". Do you mean it should be extracted as a prep commit here, or a commit at the end of this PR, or as a different follow-up PR all together? |
I would be inclined to do the change of moving things to |
6ade50a
to
7d54b38
Compare
630cf6d
to
f15be09
Compare
I've done some splitting of commits to try to make this more readable. The last commit is still huge (200+ lines), but a lot of it is |
f15be09
to
f29e588
Compare
fa49d09
to
b50ad66
Compare
I got this test failure nondeterministically when running tests in parallel with the second commit included. Haven't tried to debug.
|
OK I merged most of the prep commits through 52a86d9, since they're independent of that issue. |
{ | ||
pattern: "ZGROUP_(?P<id>[0-9]{2,8}):(?P<zone>[0-9]{1,8})", | ||
url_format: "https://zone_%(zone)s.zulip.net/ticket/%(id)s", | ||
}, |
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.
Should these examples have an ID field too?
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.
They aren't required for these tests -- the id
s are used in only the settings page, but I'll add them here too for completeness.
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.
Done!
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.
I also did this treatment to a couple other instances in this file which the commit touches, so that these dictionaries are complete even if we aren't testing all of the fields.
b50ad66
to
368937c
Compare
686c5e2
to
873c717
Compare
@timabbott The main commit here is ready for another review. I've addressed #17596 (comment). |
Is there a way to run only a few tests parallelly, without doing the whole of |
873c717
to
3c948f5
Compare
@abhijeetbodas2001 yeah, you can do |
* This introduces a new event type `realm_linkifiers` and a new key for the initial data fetch of the same name. Newer clients will be expected to use these. * Backwards compatibility is ensured by changing neither the current event nor the /register key. The data which these hold is the same as before, but internally, it is generated by processing the `realm_linkifiers` data. We send both the old and the new event types to clients whenever the linkifiers are changed. Older clients will simply ignore the new event type, and vice versa. * The `realm/filters:GET` endpoint (which returns tuples) is currently used by none of the official Zulip clients. This commit replaces it with `realm/linkifiers:GET` which returns data in the new dictionary format. TODO: Update the `get_realm_filters` method in the API bindings, to hit this new URL instead of the old one. * This also updates the webapp frontend to use the newer events and keys.
3c948f5
to
3947b0c
Compare
This is great, merged, thanks @abhijeetbodas2001! I made the following tweaks to documentation while merging:
|
@abhijeetbodas2001 I think as a natural follow-up, we should change the |
I've also opened issues for mobile and terminal to migrate to the new format. Thanks for doing this @abhijeetbodas2001! It's very nice to be on a path to eliminating these weird tuple quirks from our API documentation. |
Yay! I think that leaves just |
Thanks. Pretty dumb of me to not look at |
Let me compile a list of TODOs from here-
@timabbott I would like to tackle all of these. Is the priority order correct? |
https://chat.zulip.org/#narrow/stream/49-development-help/topic/Nullable.20element.20in.20TupleType
This adds new event type
realm_linkifier
which uses dictionaries instead of tuples.Testing plan:
This PR updates the webapp frontend to handle the new-type events, but I also tested manually before making the frontend changes to verify that the old style events are still sent as before.