Fix NameError: ensure df is defined before saveAsTable in lab 03#373
Closed
Fix NameError: ensure df is defined before saveAsTable in lab 03#373
df is defined before saveAsTable in lab 03#373Conversation
Co-authored-by: v-mohamrafi <263783887+v-mohamrafi@users.noreply.github.com> Agent-Logs-Url: https://github.com/MicrosoftLearning/mslearn-fabric/sessions/96cd4557-a20b-48de-9bba-ea52ad79b0b4
Copilot
AI
changed the title
[WIP] Fix NameError: name 'df' is not defined in managed table code
Fix NameError: ensure Mar 23, 2026
df is defined before saveAsTable in lab 03
v-mohamrafi
reviewed
Mar 23, 2026
Collaborator
v-mohamrafi
left a comment
There was a problem hiding this comment.
Executed the code manually with error of bug and cross verified with @copilot suggestions.
weslbo
reviewed
Mar 25, 2026
Collaborator
weslbo
left a comment
There was a problem hiding this comment.
This extra line of code is not necessary. At line 89, we already instantiate the dataframe with a spark.read call, so it's not necessary anymore to do it again at line 125
weslbo
reviewed
Mar 25, 2026
Collaborator
weslbo
left a comment
There was a problem hiding this comment.
Will close this PR as the extra line of code is not necessary. At line 89, we already instantiate the dataframe with a spark.read call, so it's not necessary anymore to do it again at line 125
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the "Create a managed table" step, the code cell called
df.write.format("delta").saveAsTable("managed_products")without guaranteeingdfwas in scope — triggeringNameError: name 'df' is not definedif the Spark session had restarted or cells were run out of order.Change
Reuses the
schemavariable already defined earlier in the notebook, preserving correct data types (e.g.,ListPriceasDoubleType).Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.