MediaMath / t1-python

Python SDK for MediaMath Platform APIs
https://developer.mediamath.com/
Apache License 2.0
18 stars 30 forks source link

strategy re-save on validation error fails #69

Closed FodT closed 8 years ago

FodT commented 8 years ago

Happens any time you get a validation error on strategy save, only way i've discovered to workaround is to re-create/pull the entity. Looks like there's some kind of corruption happening.

>>> s = t1.new(models.Strategy)
>>> s.campaign_id = CAMPAIGN_ID
>>> s.name = 'test kepler strategy'
>>> s.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/t1-python/terminalone/models/strategy.py", line 194, in save
    super(Strategy, self).save(data=data, url=url)
  File "/t1-python/terminalone/entity.py", line 247, in save
    entity, _ = super(Entity, self)._post(PATHS['mgmt'], url, data=data)
  File "/t1-python/terminalone/connection.py", line 118, in _post
    result = self._parser(response_body)
  File "/t1-python/terminalone/xmlparser.py", line 27, in __init__
    self.get_status(result, xml)
  File "/t1-python/terminalone/xmlparser.py", line 75, in get_status
    raise exc(code=status_code, content=message)
terminalone.errors.ValidationError: invalid
budget (code: 3): Budget is a required field.
pacing_amount (code: 3): Pacing Amount is a required field.
goal_type (code: 3): Goal Type is a required field.
type (code: 3): Type is a required field.
>>> s.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/t1-python/terminalone/models/strategy.py", line 182, in save
    self.pixel_target_expr = self._serialize_target_expr()
  File "/t1-python/terminalone/models/strategy.py", line 168, in _serialize_target_expr
    include_bool = '] {} ['.format(self.pixel_target_expr['include']['operator'] or 'OR')
TypeError: string indices must be integers
FodT commented 8 years ago

Looks like this is being caused by _serialize_target_expr being called twice.