I have code running on a server with namedtuples:
Event = namedtuple("Event", ['attr1', 'attr2', 'attr3'])
The server is getting events from other servers, coming out of a queue.
I want to add a new feature to my code which needs a new attribute in the namedtuple. Is there a good way to do this and keep backwards compatibility? That is, I can stop and start the server, and change the code to:
Event = namedtuple("Event", ['attr1', 'attr2', 'attr3', 'attr4'])
But in the meantime there will be Events with the old signature queued up.
Anyone done this before?
It would work as it is, only problem can occur is in your code when you are using the newly added attribute e.g.
You will get error
AttributeError: 'Event' object has no attribute 'attr5'so if you taken care of such thing in backward-compatible way, like checking if attr5 is there, it should work