Skip to content

Commit fc9b3fb

Browse files
committed
Fix and unittest issue with outerjoin
1 parent 14d058a commit fc9b3fb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

datatables/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_attr(sqla_object, attribute):
3434
if type(output) is InstrumentedList:
3535
output = ', '.join([getattr(elem, x) for elem in output])
3636
else:
37-
output = getattr(output, x)
37+
output = getattr(output, x, None)
3838
return output
3939

4040

tests/test_datatables.py

+22
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,25 @@ def test_column_ordering_relation(self):
318318
res = rowTable.output_result()
319319

320320
assert res['data'][0]['2'] == '000_aaa'
321+
322+
def test_outerjoin(self):
323+
"""Test if outerjoin works."""
324+
self.populate(5)
325+
f = faker.Faker()
326+
a = Address(description=f.address())
327+
self.session.add(a)
328+
329+
columns = self.create_columns(['id', 'description', 'user.name'])
330+
331+
req = self.create_dt_params()
332+
333+
rowTable = DataTables(
334+
req, Address, self.session.query(Address).outerjoin(User), columns)
335+
336+
res = rowTable.output_result()
337+
338+
assert len(res['data']) == 6
339+
assert res['recordsTotal'] == '6'
340+
assert res['recordsFiltered'] == '6'
341+
assert res['data'][5]['1'] == a.description
342+
assert res['data'][5]['2'] == 'None'

0 commit comments

Comments
 (0)