django-dbbackup icon indicating copy to clipboard operation
django-dbbackup copied to clipboard

feat(pg_dump): Add '--if-exists' option for pg_dump (and add tests)

Open WillNilges opened this issue 1 year ago • 5 comments
trafficstars

Description

  • Adds --if-exists option for pg_dump command
  • Resolves #478
  • Adds simple test

Extension of #511. If I understand correctly this was precluded on missing a test? I have added it, and was hoping to get this merged so I can use it in production 🙇🏻

Feel free to cherry pick my commit onto @DmytroLitvinov's PR or however you want to do it, I just wanted the feature to move 😅

Checklist

Please update this checklist as you complete each item:

  • [X] Tests have been developed for bug fixes or new functionality.
  • [ ] The changelog has been updated, if necessary.
  • [ ] Documentation has been updated, if necessary.
  • [X] GitHub Issues closed by this PR have been linked.

By submitting this pull request I agree that all contributions comply with this project's open source license(s).

WillNilges avatar Apr 02 '24 05:04 WillNilges

Hi @WillNilges , Thanks for the help 👍

Added your commit into my initial PR: https://github.com/jazzband/django-dbbackup/pull/511

DmytroLitvinov avatar Apr 02 '24 06:04 DmytroLitvinov

Just a heads up that this test seems to be broken.

Archmonger avatar Apr 02 '24 22:04 Archmonger

Oops, that's my bad. Should work now.

WillNilges avatar Apr 06 '24 01:04 WillNilges

Marking this as draft due to tests failing

Archmonger avatar Aug 22 '24 21:08 Archmonger

The following error will need to be resolved

  Traceback (most recent call last):
    File "/home/runner/work/django-dbbackup/django-dbbackup/.tox/py38-django42/lib/python3.8/site-packages/gnupg.py", line 159, in _copy_data
      outstream.write(data)
  TypeError: a bytes-like object is required, not 'str'
  ....ERROR Exception: Foo
    File "/home/runner/work/django-dbbackup/django-dbbackup/dbbackup/utils.py", line 119, in wrapper
      func(*args, **kwargs)
    File "/home/runner/work/django-dbbackup/django-dbbackup/dbbackup/tests/test_utils.py", line 81, in func
      raise Exception("Foo")
  
  .ERROR Exception: Foo
    File "/home/runner/work/django-dbbackup/django-dbbackup/dbbackup/utils.py", line 119, in wrapper
      func(*args, **kwargs)
    File "/home/runner/work/django-dbbackup/django-dbbackup/dbbackup/tests/test_utils.py", line 91, in func
      raise Exception("Foo")
  
  ..ERROR Error sending data
  Traceback (most recent call last):
    File "/home/runner/work/django-dbbackup/django-dbbackup/.tox/py38-django42/lib/python3.8/site-packages/gnupg.py", line 159, in _copy_data
      outstream.write(data)
  TypeError: a bytes-like object is required, not 'str'

Somehow your changes broke test_raise_error_without_mail

    @patch("dbbackup.settings.SEND_EMAIL", False)
    def test_raise_error_without_mail(self):
        def func():
            raise Exception("Foo")

        with self.assertRaises(Exception):
            utils.email_uncaught_exception(func)()
        self.assertEqual(len(mail.outbox), 0)

Specifically, it seems like gnupg is trying to encrypt some values before sending the email but it is receiving a string instead of bytes.

Truthfully, I am not sure how your changes could have caused this.

Archmonger avatar Aug 23 '24 23:08 Archmonger