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

AttributeError when deepcopying object using structlog #268

Closed
stefanbschneider opened this issue Jun 25, 2020 · 4 comments · Fixed by #270
Closed

AttributeError when deepcopying object using structlog #268

stefanbschneider opened this issue Jun 25, 2020 · 4 comments · Fixed by #270

Comments

@stefanbschneider
Copy link
Contributor

I really like structlog and have been using it in my classes like this:

class Test:
    def __init__(self, id, works=True):
        self.id = id
        self.works = works
        self.log = structlog.get_logger(id=self.id)

    def example(self):
        self.log.info('Works')

This way I have separate loggers for different objects to which I can bind different attributes (here id). And it used to work fine.

Now, I need to deepcopy my objects and it breaks:

test = Test(1)
copied_test = deepcopy(test)

This fails with the following error: AttributeError: 'PrintLogger' object has no attribute '__deepcopy__'

Is there some other best practice how to use structlog with classes and objects? Or some way to fix the problem?

This seems related to #126 and #71.
I have structlog 20.1.0 with Python 3.8 on Ubuntu 20.04 (on WSL on Win 10).

@hynek
Copy link
Owner

hynek commented Jun 25, 2020

Yeah I suppose we'll have to implement an __deepcopy__ analogously to the pickle code.

@stefanbschneider
Copy link
Contributor Author

Any way I can help with this?

@hynek
Copy link
Owner

hynek commented Jun 29, 2020

You could submit a PR that does it? 😇 Shouldn't be too complicated, I think.

The bigger problem will probably be to hunt down all classes that need this treatment. 🤔

@stefanbschneider stefanbschneider mentioned this issue Jun 30, 2020
6 tasks
@stefanbschneider
Copy link
Contributor Author

Hm, fixing PrintLogger worked, but I still get errors: #270 Do you have any idea what the cause could be?

@hynek hynek closed this as completed in #270 Nov 4, 2020
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

Successfully merging a pull request may close this issue.

2 participants