Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logCompaction data restriction #67

Open
SantjagoCorkez opened this issue Sep 19, 2017 · 1 comment
Open

logCompaction data restriction #67

SantjagoCorkez opened this issue Sep 19, 2017 · 1 comment

Comments

@SantjagoCorkez
Copy link

As of https://github.com/bakwc/PySyncObj/blob/master/pysyncobj/syncobj.py#L1282 logCompaction dumps all the properties of a SyncObj instance that are not listed in SyncObj.__properies (note a typo). That dataset, being collected via self.__properies surely includes subclass'es own properties.

Since the base SyncObj class is designed to be subclassed and some business logic to be implemented on top of this, there surely might be many properties related to that logic. In my case they include some data receiving/emitting sockets. Since sockets can't be pickled or serialized another way that leads to logCompaction failure.

  1. Note an attribute typo
  2. Can the data included to logCompaction mechanism restricted to not include some data programmatically? Another (and I think more preferrable) way: restrict logCompaction to collect only the data fields that are specially registered to be included.

For now I have to use an ugly method of self._dict__['_SyncObj__properies'].update({'myfield1', 'myfield2', ...})

@bakwc
Copy link
Owner

bakwc commented Sep 19, 2017

Thanks for report. There is several possibilities to achieve skipping members serialization. First one is declare all members that should not be serialized before running init of SyncObj:

class SomeClass(SyncObj):
    def __init__(self):
        self.a = 10 # will NOT be serialized
        super(SomeClass, self).__init__(...)
        self.b = 20 # will be serialized

Second approach is to declare your own serializer and deserializer function.
And the last one is to stop inheriting from SyncObj, instead write your own class which will have SyncObj as a member, and also have one or many SyncObjConsumers. Consumers will store only state-machine data and logic, and all members that don't need to be serialized should be moved out of consumers.

Another (and I think more preferrable) way: restrict logCompaction to collect only the data fields that are specially registered to be included.

May be it is a good idea, but I don't want to make any significant changes into interface and break backward compatibility. But I'll try to think what we can do here. Current way is not very obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants