-
Notifications
You must be signed in to change notification settings - Fork 21
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
Small issues with prerun.py
#24
Comments
I found an additional issue just now. Issue: Missing
|
Looks like this specific issue was resolved in PR #34. The original issues still seem to be relevant. |
Overview
While testing out creation of a custom CKAN 2.10 image, I found some issues with
ckan-2.10/base/setup/prerun.py
. At a quick glance, these issues also affect the CKAN 2.9 version of the file.Issue:
TypeError
can be raised inexcept subprocess.CalledProcessError
blocksIn both
init_db()
andinit_datastore_db()
, the following logic occurs:If this
except
block is encountered, then the script will fail with aTypeError
because the type ofe.output
isbytes
, notstr
.Demonstration
Using the
ckan/ckan-docker
setup, I modifiedprerun.py
in the following way, to make thedb_command
insideinit_db()
invalid:When I started the Docker containers, the script failed with a
TypeError
:Suggested Fix
There are multiple ways that this could be addressed. One option is to modify the invocations of
subprocess.Popen
andsubprocess.check_output
to explicitly open the output stream in text mode. Based on howe.output
is used, I think that this is probably what is intended. Per the official documentation forsubprocess
:To demonstrate, I implemented this change by adding
text=True
inside thesubprocess.check_output()
call:Here are the results -- the
TypeError
does not happen anymore.It looks like
text
was added in Python 3.7, which is the minimum supported version for CKAN, so adding that flag should be a reasonable thing to do.Final Note
As a final note, the documentation on
subprocess
Exceptions and thesubprocess.CalledProcessError
docs both seem to suggest thatsubprocess.Popen()
will not raise aCalledProcessError
, so it is possible that theexcept subprocess.CalledProcessError
block ininit_database_db()
is actually unnecessary (or needs to catch a different Exception).Issue: Unnecessary import of
re
insidecheck_solr_connection()
There is an unnecessary import of
re
in anexcept
block insidecheck_solr_connection()
.There is also a lot of unnecessary trailing whitespace on the lines in that same
except
block.The text was updated successfully, but these errors were encountered: