gpload fails with "UnboundLocalError: local variable 'has_seq_bool' referenced before assignment" when loading into tables with sequence-backed columns
search cancel

gpload fails with "UnboundLocalError: local variable 'has_seq_bool' referenced before assignment" when loading into tables with sequence-backed columns

book

Article ID: 443933

calendar_today

Updated On:

Products

VMware Tanzu Greenplum VMware Tanzu Greenplum / Gemfire

Issue/Introduction

gpload may fail during table metadata discovery when loading data into a table that contains a sequence-backed column, such as a column defined using DEFAULT nextval(...).

The failure occurs before any data is loaded and gpload terminates with an error similar to:

Traceback (most recent call last):
  File "/usr/local/greenplum-db-7.x.x/bin/gpload.py", line XXXX, in run
    self.run2()
  File "/usr/local/greenplum-db-7.x.x/bin/gpload.py", line XXXX, in run2
    self.read_table_metadata()
  File "/usr/local/greenplum-db-7.x.x/bin/gpload.py", line XXXX, in read_table_metadata
    i = [name,ct,None, has_seq_bool]

UnboundLocalError: local variable 'has_seq_bool' referenced before assignment

Cause

This issue is caused by a defect in the gpload metadata processing logic introduced in the GPDB 7.x code path.

In gpload.py, the sequence detection logic contains an incorrect variable assignment:

has_seq = row['has_sequence']

if has_seq == str('f') or has_seq == False:
    has_seq_bool = False

if has_seq == str('t') or has_seq == True:
    has_sql_bool = True

i = [name,ct,None, has_seq_bool]

When a sequence-backed column is detected (has_seq=True), the code assigns a value to has_sql_bool, but later references has_seq_bool, which was never initialized. This results in the observed UnboundLocalError.

Resolution

Resolution

Engineering has fixed this issue and the fix is planned for inclusion in Greenplum 7.8.3.

Customers should upgrade to a release containing the fix once it becomes available.

 

Workaround

Customer can modify gpload.py until the fix is released by following below steps:

  1. Create a backup of the existing file:
cp /usr/local/greenplum-db-clients-<version>/bin/gpload.py /usr/local/greenplum-db-clients-<version>/bin/gpload.py.bak
  1. Edit the file:
vi /usr/local/greenplum-db-clients-<version>/bin/gpload.py
  1. Locate the following code block:
if has_seq == str('t') or has_seq==True:
    has_sql_bool = True
  1. Replace it with:
if has_seq == str('t') or has_seq==True:
    has_seq_bool = True
  1. Save the file and rerun the gpload job.

The workaround was validated in a GPDB 7.x and allowed the load to complete successfully.