3

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
speedplane
  • 15,673
  • 16
  • 86
  • 138
  • FWIW, passing the same `--watcher_ignore_re="(.*\.git|.*\.idea|tmp\.py)"` argument on linux works just fine. Might be a windows-specific issue. Check your quotations if you didn't do that already. Remove or modify your args, including `watcher_ignore_re` to see if you isolate which arg piece exactly is the upsetting one. – Dan Cornilescu Jun 06 '18 at 17:41
  • @DanCornilescu, could you please expand on what you explain in your comment and post it as an answer? Thank you. – Rodrigo C. Jun 08 '18 at 11:48
  • 2
    Same thing happens to me for ` --watcher_ignore_re '.*/frontend/.*'` on a Mac. SDK version 204.0.0. This is a new issue, it worked fine when I was on the previous version of the SDK. – Kostub Deshmukh Jun 12 '18 at 20:34
  • 2
    I reverted to SDK version 200.0.0 and the issue is fixed. – Kostub Deshmukh Jun 20 '18 at 22:38

2 Answers2

5

It looks like it is an issue with the google analytics code built into dev_appserver2 (google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py on or around line 316). It wants to send all of your command line options to google analytics. If you remove the analytics client id by adding the command line option --google_analytics_client_id= (note: '=' without any following value) the appserver won't call the google analytics code where it is trying to JSON serialize an SRE object and failing. However, since you are on Windows I find that the --watcher_ignore_re does not work anyway even when you get past this issue.

There is a comment in file_watcher.py

TODO: b/33178251 - Add watcher_ignore_re support for windows.

akwebb1
  • 198
  • 6
  • 9
1

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 :)

Pavlo Zhukov
  • 3,007
  • 3
  • 26
  • 43