Skip to content
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

Error "TypeError: must be real number, not TemplatedDictionary" when %2F in base path #639

Closed
sonneveld opened this issue Oct 2, 2020 · 5 comments · Fixed by #640
Closed
Assignees

Comments

@sonneveld
Copy link

Error "TypeError: must be real number, not TemplatedDictionary" when %2F in base path

For context, we create custom mock environments for our jenkins builds and for some reason, one of our nodes started creating workspace directories with "%2F" in the name. It looks like mock is trying to do variable substitution for the values, which gets confused with %2F

Output of rpm -q mock

mock-2.4-1.el7.noarch

Steps to reproduce issue

  1. Create new mock config directory with a default.cfg, logging.ini and site-defaults.cfg
  2. In site-defaults.cfg, set base dir and cache_topdir to a path with %2F in it
  3. Run mock with mock --configdir=$CONFIGDIR --shell

site-defaults.cfg:

config_opts['basedir'] = '/data/jenkins/workspace/abc-group/abc%2Fabc/MR-123/abc/build/work/abc/mock/base'
config_opts['cache_topdir'] = '/data/jenkins/workspace/abc-group/abc%2Fabc/MR-123/abc/build/work/abc/mock/cache'

You'll get an error along the lines of

16:39:43  ERROR: must be real number, not TemplatedDictionary
16:39:43  Traceback (most recent call last):
16:39:43    File "/usr/libexec/mock/mock", line 1026, in <module>
16:39:43      exitStatus = main()
16:39:43    File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
16:39:43      result = func(*args, **kw)
16:39:43    File "/usr/libexec/mock/mock", line 655, in main
16:39:43      util.set_config_opts_per_cmdline(config_opts, options, args)
16:39:43    File "/usr/lib/python3.6/site-packages/mockbuild/trace_decorator.py", line 93, in trace
16:39:43      result = func(*args, **kw)
16:39:43    File "/usr/lib/python3.6/site-packages/mockbuild/util.py", line 1437, in set_config_opts_per_cmdline
16:39:43      if is_in_dir(config_opts['resultdir'] % config_opts, basechrootdir):
16:39:43  TypeError: must be real number, not TemplatedDictionary
@xsuchy
Copy link
Member

xsuchy commented Oct 2, 2020

Hmm, simple reproducer:

$ python3
Python 3.9.0rc2 (default, Sep 17 2020, 00:00:00) 
[GCC 10.2.1 20200826 (Red Hat 10.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mockbuild.util import TemplatedDictionary
>>> a=TemplatedDictionary()
>>> b='/data/jenkins/workspace/abc-group/abc%2Fabc/MR-123/abc/build/work/abc/mock/base'
>>> 
>>> a.__render_string(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TemplatedDictionary' object has no attribute '__render_string'
>>> a["x"]=b
>>> a
<mockbuild.util.TemplatedDictionary object at 0x7f020f24f460>, TemplatedDictionary({'_aliases': {}, 'x': '/data/jenkins/workspace/abc-group/abc%2Fabc/MR-123/abc/build/work/abc/mock/base'})
>>> a["x"]
'/data/jenkins/workspace/abc-group/abc%2Fabc/MR-123/abc/build/work/abc/mock/base'
>>> config_opts['resultdir'] % {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'config_opts' is not defined
>>> a['x'] % {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not dict

@xsuchy
Copy link
Member

xsuchy commented Oct 2, 2020

Hmm... that expansion is there because of %(uid)s %(gid)s %(home)s %(user)s etc. We basically will have this historic expansion or this error.
It has been quite a time since the deployment of TemplatedDictionary. I am proposing to declare that that old expansion is not supported. Then we can remove the % config_opts part and this issue will be resolved. What do you think @praiskup ?

@praiskup
Copy link
Member

praiskup commented Oct 3, 2020

I think we can put the removal of the %(config_opts) expansion on schedule...

But first I think we should detect if the expansion makes at least some sense (e.g. by checking for %( presence),
and warn the user:

def expand_config(string, config):
    if '%(' in string:
        warn_about_obsoleted_syntax
        return string % config
    return config

@praiskup praiskup self-assigned this Oct 4, 2020
praiskup added a commit to praiskup/mock that referenced this issue Oct 4, 2020
praiskup added a commit to praiskup/mock that referenced this issue Oct 6, 2020
praiskup added a commit that referenced this issue Oct 6, 2020
@sonneveld
Copy link
Author

Sweet. Thanks everyone.

@praiskup
Copy link
Member

praiskup commented Oct 7, 2020

FTR, pre-release builds are in dnf copr enable @mock/mock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants