flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Deprecated-but-readable table fields?

Open maxburke opened this issue 1 year ago • 7 comments

I'm wondering if there's a way to have fields that are deprecated for writing, but still have read accessors available. We have a bunch of serialized objects where we would like to soft-migrate to the non-deprecated attributes, but would still like to read the old values if they exist.

maxburke avatar May 08 '23 16:05 maxburke

Not off the top of my head. We could add an attribute to only deprecate the writing part.

dbaileychess avatar May 08 '23 21:05 dbaileychess

I would take a PR for this if you are interested, not high enough on my list to do myself.

dbaileychess avatar May 10 '23 16:05 dbaileychess

@dbaileychess Understandable, let me see if I can fit it in.

What would you think of the name readonly for the attribute?

maxburke avatar May 10 '23 16:05 maxburke

I think I would prefer deprecated_writes or something, to indicate that the field is in progress to be deprecated.

Or deprecated_readonly would work.

dbaileychess avatar May 10 '23 16:05 dbaileychess

I would also have the use for that feature!

stephanemagnenat avatar Sep 21 '23 08:09 stephanemagnenat

Yes! Every time I reach for the deprecated attribute, I find that something like this is what I actually need, since I must keep backwards compatibility. I usually end up just renaming the field foo_deprecated to indicate that it's not supposed to be written, but it would be nice to have something like deprecated_readonly or whatever so that it would be a compile error to write to it, even by accident.

Zguy avatar Dec 18 '23 14:12 Zguy

I felt inspired, and made an attempt at an implementation. PR here: https://github.com/google/flatbuffers/pull/8192

Zguy avatar Dec 20 '23 23:12 Zguy