Skip to content

Commit

Permalink
[AIRFLOW-443] Make module names unique when importing
Browse files Browse the repository at this point in the history
Module names are normalized to "unusual_prefix_<filename>" in case
of non-ZIP imports. If there are two modules with the same filename
in a different directory they can overwrite each other. This is
exhibited by the looking at the code from the web interface.

This is fixed by using a hash of the filepath in the normalization.
The hash is required to stay compatible with Python 2.
  • Loading branch information
bolkedebruin committed Aug 21, 2016
1 parent 3cba29e commit 14c868e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import textwrap
import traceback
import warnings
import hashlib

from urllib.parse import urlparse

from sqlalchemy import (
Expand Down Expand Up @@ -245,7 +247,9 @@ def process_file(self, filepath, only_if_updated=True, safe_mode=True):

self.logger.debug("Importing {}".format(filepath))
org_mod_name, _ = os.path.splitext(os.path.split(filepath)[-1])
mod_name = 'unusual_prefix_' + org_mod_name
mod_name = ('unusual_prefix_'
+ hashlib.sha1(filepath.encode('utf-8')).hexdigest()
+ '_' + org_mod_name)

if mod_name in sys.modules:
del sys.modules[mod_name]
Expand Down

0 comments on commit 14c868e

Please sign in to comment.