Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
MaryJo
Frequent Visitor

Notebook: AttributeError: 'NoneType' object has no attribute 'alias'

Question on running a notebook using pyspark.sql.  I am loading multiple files into a new table that is specified in the notebook.  The notebook loads the first file successfully then all other files it throws out the error such as the below.  The code fails around line 79 when processing the sebsequent files.  I will also paste in the notebook code at line 79 for reference.  Trying to figure out how to fix the attribute error stating 'Nonetype' object has no attribute 'alias'.

 

MaryJo_0-1735318136680.png

 

Notebook line 79 code.

 

MaryJo_1-1735318247854.png

If anyone has any suggestions that would be great.  Thank you for your time.

 

1 ACCEPTED SOLUTION
v-shamiliv
Community Support
Community Support

Hi @MaryJo
Thank you for reaching out Microsoft fabric community forum.

The error AttributeError: 'NoneType' object has no attribute 'alias' suggests that the delta_table object isn’t being set up correctly when moving on to the next files.

  • Double-check that the Delta table exists at the specified path. If it doesn't, you'll encounter this error.
  •  Make sure the path_to_delta_table is correct and accessible. path issues can cause problems.
  •  Adding some print statements can help you determine if delta_table is None before you use it. This way, you can see where things might be going wrong.
    delta_table = DeltaTable.forPath(spark, path_to_delta_table)
    if delta_table is None:
    print("Delta table not found or created successfully.")
    else:
    keyfield_lines = raw_df.rdd.map(lambda row: row[0]).collect()[0]
    keyfields = keyfield_lines.replace("KeyFields=", "").split(",")
    condition = " AND ".join([f"old_data.{field} = new_data.{field}" for field in keyfields])
    delta_table.alias("old_data").merge(df.alias("new_data"), condition) \
    .whenMatchedUpdateAll() \
    .whenNotMatchedInsertAll() \
    .execute()
  • Ensure the Delta table is set up correctly during the first write operation. If the initial write isn't successful, the table won't exist for subsequent operations.

    By following these steps, you will be able to fix the issue causing the NoneType error.

     

    If you need any further assistance or have any questions, please feel free to contact us.


    If this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community.
    Best regards,
    shamili.v

 

View solution in original post

2 REPLIES 2
v-shamiliv
Community Support
Community Support

Hi @MaryJo
Thank you for reaching out Microsoft fabric community forum.

The error AttributeError: 'NoneType' object has no attribute 'alias' suggests that the delta_table object isn’t being set up correctly when moving on to the next files.

  • Double-check that the Delta table exists at the specified path. If it doesn't, you'll encounter this error.
  •  Make sure the path_to_delta_table is correct and accessible. path issues can cause problems.
  •  Adding some print statements can help you determine if delta_table is None before you use it. This way, you can see where things might be going wrong.
    delta_table = DeltaTable.forPath(spark, path_to_delta_table)
    if delta_table is None:
    print("Delta table not found or created successfully.")
    else:
    keyfield_lines = raw_df.rdd.map(lambda row: row[0]).collect()[0]
    keyfields = keyfield_lines.replace("KeyFields=", "").split(",")
    condition = " AND ".join([f"old_data.{field} = new_data.{field}" for field in keyfields])
    delta_table.alias("old_data").merge(df.alias("new_data"), condition) \
    .whenMatchedUpdateAll() \
    .whenNotMatchedInsertAll() \
    .execute()
  • Ensure the Delta table is set up correctly during the first write operation. If the initial write isn't successful, the table won't exist for subsequent operations.

    By following these steps, you will be able to fix the issue causing the NoneType error.

     

    If you need any further assistance or have any questions, please feel free to contact us.


    If this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community.
    Best regards,
    shamili.v

 

Thank you very much for your detailed explanation and this resolved our issue.  

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.