4973: rbt patch - SVN - failing with "a bytes-like object is required, not 'str'"

rpowell
chipx86
chipx86

What version are you running?

$ rbt --version
RBTools 3.1.1 alpha 0 (dev) (Python 3.10.4)

$ svn --version
svn, version 1.14.1 (r1886195)
compiled May 21 2022, 10:52:35 on x86_64-pc-linux-gnu

What steps will reproduce the problem?

  1. Use rbt patch <number> to apply an SVN patch.

What is the expected output? What do you see instead?

Expected output
Applying 1 patch ...

Actual output:

$ rbt patch 269193
Applying 1 patch from review request 269193 (diff revision 5)

CRITICAL: a bytes-like object is required, not 'str'

What operating system are you using?

Ubuntu 22.04

Attach the debug out from the command.

$ rbt <command> --debug <args>
<snip>
>>> Making HTTP GET request to https://<server>/api/review-requests/269193/?force-text-type=plain
>>> Cached response for HTTP GET https://<server>/api/review-requests/269193/?force-text-type=plain expired and was not modified
Applying 1 patch from review request 269193 (diff revision 5)
>>> Running: svn --non-interactive patch --strip=3 /tmp/rbtools.z81jtd4j

Traceback (most recent call last):
  File "/home/bpowell/dev/rbt/rb_venv/bin/rbt", line 33, in <module>
    sys.exit(load_entry_point('RBTools', 'console_scripts', 'rbt')())
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/main.py", line 207, in main
    command.run_from_argv([RB_MAIN, command_name] + args)
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/__init__.py", line 1096, in run_from_argv
    exit_code = self.main(*args) or 0
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/patch.py", line 536, in main
    self._apply_patches(patches)
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/patch.py", line 635, in _apply_patches
    success = self.apply_patch(
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/patch.py", line 363, in apply_patch
    self.stdout_bytes.write(patch_output)
  File "/home/bpowell/dev/rbt/rbtools/rbtools/commands/__init__.py", line 192, in write
    self.output_stream.write(msg)
TypeError: a bytes-like object is required, not 'str'

Please provide any additional information below.

The following diff appears to resolve the issue

$ diff commands/patch.py ../rbt/rbtools/rbtools/commands/patch.py 
363,366c363
<                 if isinstance(patch_output, str):
<                     self.stdout.write(patch_output)
<                 else:
<                     self.stdout_bytes.write(patch_output)
---
>                 self.stdout_bytes.write(patch_output)

Locale settings

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Issue may have been introduced under this was likely introduced in: https://github.com/reviewboard/rbtools/commit/db0c1f5b3a0ed3e132b7102c8173ab8b8ac0bc3a#diff-dbd3ec45e4478c9f27f9db6c6cfadb5d64d436dadfed8771a7c689f657b2d4c1

rpowell
#1 rpowell
  • -rbt patch - SVN
    +rbt patch - SVN - failing with "a bytes-like object is required, not 'str'"
rpowell
#2 rpowell

posted review: https://reviews.reviewboard.org/r/12372/

#3 dushara

I suggest the following patch as a fix. This mirrors the implementation of the git client:

diff --git a/rbtools/clients/svn.py b/rbtools/clients/svn.py
index e6c6e02..5dae3ec 100644
--- a/rbtools/clients/svn.py
+++ b/rbtools/clients/svn.py
@@ -1114,7 +1114,9 @@ class SVNClient(SCMClient):

     cmd.append(six.text_type(patch_file))
  • rc, patch_output = self._run_svn(cmd, return_error_code=True)
  • rc, patch_output = self._run_svn(cmd,
  • return_error_code=True,
  • results_unicode=False)
     if self.supports_empty_files():
         try:
    
#4 dushara

Trying again:

diff --git a/rbtools/clients/svn.py b/rbtools/clients/svn.py
index e6c6e02..5dae3ec 100644
--- a/rbtools/clients/svn.py
+++ b/rbtools/clients/svn.py
@@ -1114,7 +1114,9 @@ class SVNClient(SCMClient):

         cmd.append(six.text_type(patch_file))

-        rc, patch_output = self._run_svn(cmd, return_error_code=True)
+        rc, patch_output = self._run_svn(cmd,
+                                         return_error_code=True,
+                                         results_unicode=False)

         if self.supports_empty_files():
             try:
rpowell
#5 rpowell

I can confirm that works.

$ rbt --version
RBTools 3.1.1 (Python 3.8.10)

before:

$ rbt patch 269521
Applying 1 patch from review request 269521 (diff revision 17)

CRITICAL: a bytes-like object is required, not 'str'

With change:

$ diff /home/bpowell/.local/lib/python3.8/site-packages/rbtools/clients/svn.py /home/bpowell/.local/lib/python3.8/site-packages/rbtools/clients/svn.py_orig
1117,1119c1117
<         rc, patch_output = self._run_svn(cmd,
<                                          return_error_code=True,
<                                          results_unicode=False)
---
>         rc, patch_output = self._run_svn(cmd, return_error_code=True)

patch applies without error

chipx86
#6 chipx86

We'll get this into 3.1.2. Thanks!

  • -New
    +Confirmed
  • +chipx86
chipx86
#7 chipx86

Fixed in 14b3b248cc9c079453fde5df43db755f2cd90b3a. This will go into 3.1.2 and 4.0.

  • -Confirmed
    +Fixed