Repository: matrix-org/synapse

Issue:
"default" field in PushRule omitted for user-defined push rules
<!--

**IF YOU HAVE SUPPORT QUESTIONS ABOUT RUNNING OR CONFIGURING YOUR OWN HOME SERVER**:
You will likely get better support more quickly if you ask in ** #synapse:matrix.org ** ;)


This is a bug report template. By following the instructions below and
filling out the sections with your information, you will help the us to get all
the necessary data to fix your issue.

You can also preview your report before submitting it. You may remove sections
that aren't relevant to your particular case.

Text between <!-- and --​> marks will be invisible in the report.

-->

### Description

<!-- Describe here the problem that you are experiencing -->
The [spec ](https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-r0-pushrules) states that for push rules returned from the server, the field `default` is required. Synapse however seems to omit this field for user-defined rules, leading to deserialization failures for a spec-compliant client that expects it when fetching push rules.

### Steps to reproduce

- Push a user-defined push rule to synapse using `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`.
- Fetch all push rules using `GET /_matrix/client/r0/pushrules/`.
- Find the newly created rule in the returned ruleset. It doesn't have a `default` field.

<!--
Describe how what happens differs from what you expected.

If you can identify any relevant log snippets from _homeserver.log_, please include
those (please be careful to remove any personal or private data). Please surround them with
``` (three backticks, on a line on their own), so that they are formatted legibly.
-->

Since the spec states that the `default` field is required, I did not expect the server to be allowed to omit it.

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: private, not federating

<!--
 What version of Synapse is running?

You can find the Synapse version with this command:

$ curl http://localhost:8008/_synapse/admin/v1/server_version

(You may need to replace `localhost:8008` if Synapse is not configured to
listen on that port.)
-->
- **Version**: 1.7.3

- **Install method**: Ansible playbook from https://github.com/spantaleev/matrix-docker-ansible-deploy
<!-- examples: package manager/git clone/pip  -->

- **Platform**: Docker in Ubuntu running on a VPS.
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->



Discussion:

Resolving patch:
diff --git a/synapse/storage/data_stores/main/push_rule.py b/synapse/storage/data_stores/main/push_rule.py
--- a/synapse/storage/data_stores/main/push_rule.py
+++ b/synapse/storage/data_stores/main/push_rule.py
@@ -41,6 +41,7 @@ def _load_rules(rawrules, enabled_map):
         rule = dict(rawrule)
         rule["conditions"] = json.loads(rawrule["conditions"])
         rule["actions"] = json.loads(rawrule["actions"])
+        rule["default"] = False
         ruleslist.append(rule)
 
     # We're going to be mutating this a lot, so do a deep copy


Test patch: