-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy dir if symlink fails #7447
Conversation
if system.path_exists(dest_path): | ||
if not system.path_is_symlink(dest_path): | ||
system.rmdir(dest_path) | ||
else: | ||
system.remove_file(dest_path) | ||
|
||
if can_create_symlink: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if can_create_symlink
check shouldn't be removed. It helps for the cases where symlink
function doesn't exist on os
, in which case AttributeError
would be thrown.
except OSError
should be added as an edge case like ours, where os.symlink
function exists but it still fails.
Something like:
symlink_supported = False
if can_create_symlink:
try:
fire_event(DepsCreatingLocalSymlink())
system.make_symlink(src_path, dest_path)
except OSError:
pass
else:
symlink_supported = True
if not symlink_supported:
fire_event(DepsSymlinkNotAvailable())
shutil.copytree(src_path, dest_path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we need it, make_symlink
calling it. The functionality remains the same. Check make_symlink method.
https://github.com/anjutiwari/dbt-core/blob/main/core/dbt/clients/system.py#L156
https://docs.getdbt.com/faqs/core/install-pip-os-prereqs.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make_symlink
method will throw dbt.exceptions.SymbolicLinkError
, in which case except OSError
block here won't handle it.
The behaviour is changed for the case where symlink
function attribute isn't present on os
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think we should use dbt.exceptions.SymbolicLinkError,
and we should also catch the SymbolicLinkError.
Also, I am curious about which OS does not have symlinks function in python lib(os)
package, as mentioned in my Issue description.
As per the dbt, we have a list of supported operating systems and condition on python3.7+. https://docs.getdbt.com/faqs/core/install-pip-os-prereqs.md
If my understanding is true, we may not have any scenarios where lib(os)
package will not have a symlink
function and we may not need to handle the SymbolicLinkError exception.
Waiting for the core reviewers to help us here.
test/unit/test_deps.py
Outdated
LocalPinnedPackage("local").install("dummy", "dummy") | ||
self.assertEqual(mock_shutil.call_count, 1) | ||
mock_shutil.assert_called_once_with("/tmp/source", "/tmp/dest") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test where system.supports_symlinks()
returns False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to handle the tests for only the newly added code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system.supports_symlinks()
check should continue to exist before trying to invoke symlink
on os
Along with that, the edge case handling of OSError
exception on system.make_symlink
should be done.
fire_event(DepsCreatingLocalSymlink()) | ||
system.make_symlink(src_path, dest_path) | ||
|
||
else: | ||
except OSError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.getdbt.com/faqs/core/install-pip-os-prereqs.md
Handling exception case of DBFS
Just a note that I think this PR fixes wider problems than just those related to databricks DBFS. When using a |
Thanks @chronitis for pointing out another edge case. Let me try to reproduce this scenario and verify if this solution is already fixing the problem. |
Hey @jtcohen6, Thank you |
Sorry for the delay in processing this. We are getting close to a release and it would be nice to get this in. Could you fix the merge conflict in test_deps.py? |
Thanks @gshank. Fixing it. |
Codecov Report
@@ Coverage Diff @@
## main #7447 +/- ##
==========================================
- Coverage 86.28% 86.26% -0.02%
==========================================
Files 174 174
Lines 25518 25518
==========================================
- Hits 22019 22014 -5
- Misses 3499 3504 +5
|
Very good point @chronitis ! This PR does look like it addresses use cases beyond Databricks DBFS, namely any time a symlink doesn't work. For example, it would also resolve #8223. |
Co-authored-by: Doug Beatty <[email protected]>
…o anjutiwari-CT-2457/dbt-deps
Co-authored-by: Anju <[email protected]>
resolves #7428
resolves #8223
Description
dbt deps command fails to run in databricks DBFS. Copy dir in case if any symlink fails with expection
Checklist
I have read the contributing guide and understand what's expected of me
I have signed the CLA
I have run this code in development and it appears to resolve the stated issue
This PR includes tests, or tests are not required/relevant for this PR
I have opened an issue to add/update docs, or docs changes are not required/relevant for this PR
I have run
changie new
to create a changelog entry