Repository: matrix-org/synapse

Issue:
Failing to sync: attr._funcs.evolve() argument after ** must be a mapping, not RoomStreamToken
Seeing these errors on latest develop (merged with #9379 -- so far that branch has worked consistently). 

```
2021-05-06 10:37:24,144 - synapse.http.server - 93 - ERROR - GET-282- Failed handle request via 'SyncRestServlet': <XForwardedForRequest at 0x7fa7e5691910 method='GET' uri='/_matrix/client/r0/sync?filter=183&timeout=0&since=s45567119_293425298_1_29910218_595864_1764_1018470_21679023_52' clientproto='HTTP/1.0' site=8018>
Traceback (most recent call last):
  File "/opt/synapse/lib/python3.9/site-packages/twisted/internet/defer.py", line 1445, in _inlineCallbacks
    result = current_context.run(g.send, result)
StopIteration: ([<FrozenEventV3 event_id='$b1vB74hFd4li3crjazdhqyhysvEk6sr_dB85hCuWzK4', type='m.room.member', state_key='@freenode_Kryptron_:matrix.org'>, <FrozenEventV3 event_id='$4fSNY9DWOo8XOOR1TrLbev_S4OWjXFGGtkYlbFs9GWs', type='m.room.member', state_key='@greatudini:matrix.org'>, <FrozenEventV3 event_id='$XXjQ2trh4wxhW7BQ15UsTtgNRerkrSw5A7OTWM4OVTY', type='m.room.message', state_key=None>, <FrozenEventV3 event_id='$1ci12KD7g0aQowO7a7NbUM8ixYNt_NunMELTBUvau_k', type='m.room.message', state_key=None>, <FrozenEventV3 event_id='$Ux9DERofhO04Smj3PcVDAPw6w7s5ihNS0xrm1qpVY3w', type='m.room.message', state_key=None>, <FrozenEventV3 event_id='$bpVth3vcA6IMHZS2GnoVxhCMywgld9I-G0sIOsHIJdc', type='m.room.message', state_key=None>], RoomStreamToken(topological=None, stream=45567154, instance_map={}))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/synapse/lib/python3.9/site-packages/twisted/internet/defer.py", line 1445, in _inlineCallbacks
    result = current_context.run(g.send, result)
  File "/opt/synapse/lib/python3.9/site-packages/synapse/handlers/sync.py", line 321, in _wait_for_sync_for_user
    result = await self.current_sync_for_user(
  File "/opt/synapse/lib/python3.9/site-packages/synapse/handlers/sync.py", line 354, in current_sync_for_user
    sync_result = await self.generate_sync_result(
  File "/opt/synapse/lib/python3.9/site-packages/synapse/handlers/sync.py", line 1020, in generate_sync_result
    res = await self._generate_sync_entry_for_rooms(
  File "/opt/synapse/lib/python3.9/site-packages/synapse/handlers/sync.py", line 1441, in _generate_sync_entry_for_rooms
    room_changes = await self._get_rooms_changed(
  File "/opt/synapse/lib/python3.9/site-packages/synapse/handlers/sync.py", line 1709, in _get_rooms_changed
    prev_batch_token = now_token.copy_and_replace("room_key", start_key)
  File "/opt/synapse/lib/python3.9/site-packages/synapse/types.py", line 657, in copy_and_replace
    return attr.evolve(self, **{key: new_value})
  File "/opt/synapse/lib/python3.9/site-packages/attr/_funcs.py", line 347, in evolve
    changes[init_name] = evolve(value, **changes[init_name])
TypeError: attr._funcs.evolve() argument after ** must be a mapping, not RoomStreamToken
```

~Looks like it could be related to #9919 ?~ See Erik's comment


Discussion:
This looks to be due to the new release of attrs 
https://github.com/python-attrs/attrs/pull/759 i think is the change
Upstream issue https://github.com/python-attrs/attrs/issues/804
Is there a way to pin this for now, I'm totally dead in the water :(
`pip install attrs==20.3.0` should revert to the previous version
Priority is to set an upper bound on the dep and roll a point release so that pip installs work as expected

Resolving patch:
diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py
--- a/synapse/python_dependencies.py
+++ b/synapse/python_dependencies.py
@@ -78,7 +78,8 @@
     # we use attr.validators.deep_iterable, which arrived in 19.1.0 (Note:
     # Fedora 31 only has 19.1, so if we want to upgrade we should wait until 33
     # is out in November.)
-    "attrs>=19.1.0",
+    # Note: 21.1.0 broke `/sync`, see #9936
+    "attrs>=19.1.0,<21.1.0",
     "netaddr>=0.7.18",
     "Jinja2>=2.9",
     "bleach>=1.4.3",


Test patch: