question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`object has no attribute` error on join

See original GitHub issue

Suppose I have a many-to-one relationship between products and departments, where both tables have a joinrow_id column. Suppose that we only have one product and its name is "chair". The chair is in the only department, whose name is “all products”, and whose “priority” is null.

I’m seeing inconsistent behavior between these two queries:

builder = Products.select(Products.name,                                                                                                                               
                          Departments.name)\
                  .join(Departments, on=(Departments.joinrow == Products.joinrow).alias('department'))\
                  .switch(Products)\
                  .where(Products.id == 1)
builder = Products.select(Products.name,                                                                                                                               
                          Departments.priority)\
                  .join(Departments, on=(Departments.joinrow == Products.joinrow).alias('department'))\
                  .switch(Products)\
                  .where(Products.id == 1)

In the first case, seemingly because the name field is truthy, I am able to type: [r for r in builder][0].department.name

But in the second case, if I try [r for r in builder][0].department.priority, the library raises an error: Products has no attribute 'department'.

This is easily remedied. I just have to make sure that, in my select, I include a column from departments whose value is always truthy.

I just wanted to bring this behavior to your attention in case you weren’t aware.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
coleifercommented, Oct 16, 2018

For your example, you should be able to workaround the “NULL” priority by also selecting the Department’s primary key, e.g.

builder = (Products
           .select(Products.name, Departments.id, Departments.priority)
           .join(Departments, on=(Departments.joinrow == Products.joinrow).alias('department'))
           .where(Products.id == 1))
1reaction
skatenerdcommented, Oct 16, 2018

I’ve created a self-contained example here:

https://gist.github.com/skatenerd/45b65a361384869e39ee20069d8ea7d4

On my machine, I’m able to make the first print statement in go(), but the second crashes with AttributeError: 'Products' object has no attribute 'department'

Read more comments on GitHub >

github_iconTop Results From Across the Web

I am getting an error as list object has no attribute 'join'
The main question is not relevant, but the title is the error I got. I mixed up the syntax trying to join a...
Read more >
attributeerror: 'list' object has no attribute 'join' - You.com
The "AttributeError: 'list' object has no attribute 'join'" occurs when we try to call the join () method on a list instead of...
Read more >
AttributeError: 'function' object has no attribute - Microsoft Learn
Using protected keywords from the DataFrame API as column names results in a function object has no attribute error message.
Read more >
I'm confusing for using .join method.. in LIST function. (Example)
sentence_list.join() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list object has no attribute ...
Read more >
AttributeError: 'function' object has no attribute - Databricks
Problem You are selecting columns from a DataFrame and you get an error message. ERROR: AttributeError: 'function' object has no attribute ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found