Search code examples
pythongoogle-app-enginedevelopment-environment

Google App Engine dev_appserver.py: watcher_ignore_re flag "is not JSON serializable"


Why I run the dev_appserver.py with the option watcher_ignore_re, I get an error message that the regex is not JSON serializable.

Is this a bug with the development server? Am I using this command improperly? The command and callstack is printed below.

C:\Users\mes65\Documents\MyProject>"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" ^
    --watcher_ignore_re="(.*\.git|.*\.idea|tmp\.py)" ^
    "C:\Users\mes65\Documents\MyProject"
WARNING  2018-06-06 09:28:59,161 appinfo.py:1622] lxml version "2.3" is deprecated, use one of: "3.7.3"
INFO     2018-06-06 09:28:59,187 devappserver2.py:120] Skipping SDK update check.
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 96, in <module>
    _run_file(__file__, globals())
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 90, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 454, in <module>
    main()
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 442, in main
    dev_server.start(options)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 163, in start
    bool(ssl_certificate_paths), options)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\metrics.py", line 166, in Start
    self._cmd_args = json.dumps(vars(cmd_args)) if cmd_args else None
  File "C:\Python27\lib\json\__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "C:\Python27\lib\json\encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\lib\json\encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "C:\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <_sre.SRE_Pattern object at 0x00000000063C2188> is not JSON serializable

Solution

  • I also faced with this usability problem on Windows and was really disappointed. I tried to find some workarounds but I hadn't found any appropriate way.

    In the end, I decided to make my own implementation of support watcher_ignore_re for Windows. I put required changes in my Github repo

    If describe them in several words:

    1. Add _watcher_ignore_re, _skip_files_re properties and its setters
    2. Add import statement from google.appengine.tools.devappserver2 import watcher_common and use it in newly created def _path_ginored
    3. Filter additional_changes before adding them to watcher changed files

    For resolving mentioned problem with not serializable regex attribute we should drop them from the serialized dictionary. Fix for this is added as consequent commit and can be checked at metrics.py:185-193.

    I hope it helps other guys enjoy developing on GAE on Windows :)