Repository: Flexget/Flexget

Issue:
Cannot use variables with integer-only values
### Expected behaviour:
Variables should be able to handle integer-only values.

### Actual behaviour:
Configuration parsing error (when using ``'{? deluge.port ?}'``): ``Got `50586`, expected: integer``
Configuration parsing error (when using ``{? deluge.port ?}``):
```
while parsing a flow mapping in "<unicode string>", line 16, column 13: port: {? deluge.port ?} ^ expected ',' or '}', but got '?' in "<unicode string>", line 16, column 28: port: {? deluge.port ?} ^
```

### Steps to reproduce:
- Step 1: Try to use below config.

#### Config:
```
    from_deluge:
      host: '{? deluge.host ?}'
      port: '{? deluge.port ?}'

```
  
#### Log:
See above.

### Additional information:

- Flexget Version: 2.10.24
- Python Version: 2.7.9
- Installation method: pip
- OS and version: macOS El Capitan 10.11.6
- Link to crash log: n/a


Discussion:
Nope, #892
I never tested this but try this `{% variable.integer | int %} `
I'm not sure what happens when you try to mix `variables` with regular jinja2 filters. 
I appreciate the thought but I got the same errors.
Looks like we could get this working using http://jinja.pocoo.org/docs/2.10/nativetypes/

Resolving patch:
diff --git a/flexget/_version.py b/flexget/_version.py
--- a/flexget/_version.py
+++ b/flexget/_version.py
@@ -7,4 +7,4 @@
 The jenkins release job will automatically strip the .dev for release,
 and update the version again for continued development.
 """
-__version__ = '2.15.2.dev'
+__version__ = '2.16.0.dev'
diff --git a/flexget/plugins/modify/variables.py b/flexget/plugins/modify/variables.py
--- a/flexget/plugins/modify/variables.py
+++ b/flexget/plugins/modify/variables.py
@@ -8,7 +8,8 @@
 
 import yaml
 
-from jinja2 import Environment, TemplateError
+from jinja2 import TemplateError
+from jinja2.nativetypes import NativeEnvironment
 
 from sqlalchemy import Column
 from sqlalchemy.sql.sqltypes import Unicode, DateTime, Integer
@@ -76,10 +77,13 @@ def process_variables(config, manager):
     }
     if 'variables' not in config or config.get('variables') is False:
         return
-    env = Environment(**env_params)
+    env = NativeEnvironment(**env_params)
     if isinstance(config['variables'], bool):
         log.debug('trying to load variables from DB')
         variables = variables_from_db()
+    elif isinstance(config['variables'], dict):
+        log.debug('loading variables from config')
+        variables = config['variables']
     else:
         log.debug('trying to load variables from file')
         variables = variables_from_file(manager.config_base, config['variables'])
@@ -113,7 +117,7 @@ def _process(element, environment):
             return None
 
 
-variables_config_schema = {'type': ['string', 'boolean']}
+variables_config_schema = {'type': ['string', 'boolean', 'object']}
 
 
 @event('config.register')


Test patch:
diff --git a/flexget/tests/test_variables.py b/flexget/tests/test_variables.py
--- a/flexget/tests/test_variables.py
+++ b/flexget/tests/test_variables.py
@@ -40,6 +40,36 @@ def test_variables_alongside_jinja(self, execute_task):
         assert task.accepted[0]['a_field'] == 'first bar then foo end'
 
 
+class TestVariablesFromConfig():
+    config = """
+      variables:
+        mock_entry_list:
+        - title: a
+        - title: b
+        integer: 2
+      tasks:
+        test_int_var:
+          mock:
+          - title: a
+          - title: b
+          - title: c
+          accept_all: yes
+          limit_new: "{? integer ?}"
+        test_var_mock:
+          mock: "{? mock_entry_list ?}"
+    """
+
+    def test_complex_var(self, execute_task):
+        task = execute_task('test_var_mock')
+        assert len(task.all_entries) == 2
+        assert task.all_entries[1]['title'] == 'b'
+
+    def test_int_var(self, execute_task):
+        task = execute_task('test_int_var')
+        assert len(task.all_entries) == 3
+        assert len(task.accepted) == 2
+
+
 class TestVariablesFromDB(object):
     config = """
         variables: yes
diff --git a/flexget/tests/variables.yml b/flexget/tests/variables.yml
--- a/flexget/tests/variables.yml
+++ b/flexget/tests/variables.yml
@@ -1,2 +1,2 @@
 test_variable: yes
-bar_var: bar
\ No newline at end of file
+bar_var: bar