Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Convert boolean event content to strings for push rule evaluation #12181

Conversation

Fizzadar
Copy link
Contributor

@Fizzadar Fizzadar commented Mar 8, 2022

Quick change so boolean event fields can be evaluated in push rules (as strings). Alternative could be a different matcher type (event_match_boolean) but that felt like overkill.

Signed of by Nick Mills-Barrett nick@beeper.com

Pull Request Checklist

@Fizzadar Fizzadar requested a review from a team as a code owner March 8, 2022 16:57
@richvdh
Copy link
Member

richvdh commented Mar 9, 2022

This does seem sensible, but I'm undecided how to handle the spec side of this.

As of matrix-org/matrix-spec-proposals#3690 (ie, current unstable spec), the spec contains the words:

If the property specified by key ... does not have a string value, then the condition will not match.

Obviously, this PR is in conflict with that.

So we've got a couple of ways to proceed:

  • Decide that this was the only sensible way to proceed, that the spec should always have allowed matching on boolean fields, that it was effectively a synapse bug that it didn't, and YOLO another PR to the spec.
  • Decide that this really is a change to existing behaviour, and that we need an MSC to change the spec in this way.

Strictly speaking I think it should be an MSC, but I'm not going to insist on a bunch of process if folks think that's ridiculous.

However, it does bring into question: what should we do about other types of fields? (In particular, numbers and nulls)

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just marking this as needing changes for now, while we consider how to proceed

@clokep
Copy link
Contributor

clokep commented Mar 9, 2022

Strictly speaking I think it should be an MSC, but I'm not going to insist on a bunch of process if folks think that's ridiculous.

However, it does bring into question: what should we do about other types of fields? (In particular, numbers and nulls)

The inconsistency between non-string types is what really makes me think the behavior should be specced. It really isn't obvious to me that you would want a boolean (or number) value to be matched as a string also.

I'd rather see this go through the MSC process, I think, but would definitely defer to people with more history of how push rules are supposed to work!

@deepbluev7
Copy link
Contributor

While I generally do want to be able to match booleans (and other types), I'm not sure if stringifying them is the right approach.

@@ -232,6 +232,8 @@ def _flatten_dict(
if result is None:
result = {}
for key, value in d.items():
if isinstance(value, bool):
value = str(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this implementation because it will give "True" and "False" as strings. Other languages represent them differently. The encoding of booleans as strings should really be specified unambiguously so push rules can be written to work on any homeserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the below string check lowercases them but it's not explicit in any way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, well, it feels less bad then (Python's capitalisation is particularly unusual, I guess), but I suppose we still ought to make it explicit in the spec how things should be stringified if this is what we're doing.

@Fizzadar
Copy link
Contributor Author

Fizzadar commented Mar 9, 2022

Given the discussion - definitely feels like this should be an MSC! I've not got much time at the moment but can probably write something up soonish.

While I generally do want to be able to match booleans (and other types), I'm not sure if stringifying them is the right approach.

I'd also lean this way, string matching on booleans feels like a hack. Same for numbers/null values.

@clokep clokep added the X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged label Mar 14, 2022
@reivilibre reivilibre added the Z-Spec-Blocked This change is blocked on specification (e.g. an MSC). label Aug 5, 2022
@clokep
Copy link
Contributor

clokep commented Aug 5, 2022

Given the discussion - definitely feels like this should be an MSC! I've not got much time at the moment but can probably write something up soonish.

For cross-linking this is MSC3758.

@Fizzadar
Copy link
Contributor Author

Closing this out, the MSC3758 takes a much better approach (match the value + type).

@Fizzadar Fizzadar closed this Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged Z-Spec-Blocked This change is blocked on specification (e.g. an MSC).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants