<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Augusta Bhardwaj</title>
    <description>The latest articles on DEV Community by Augusta Bhardwaj (@4ugusta).</description>
    <link>https://dev.to/4ugusta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4258528%2Fe8747d27-e706-48ff-9533-f8327168f63f.png</url>
      <title>DEV Community: Augusta Bhardwaj</title>
      <link>https://dev.to/4ugusta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/4ugusta"/>
    <language>en</language>
    <item>
      <title>The Google Ads API has no compare and set. Five rules for software that edits an ad account.</title>
      <dc:creator>Augusta Bhardwaj</dc:creator>
      <pubDate>Sun, 22 Nov 2026 12:07:35 +0000</pubDate>
      <link>https://dev.to/4ugusta/the-google-ads-api-has-no-compare-and-set-five-rules-for-software-that-edits-an-ad-account-48i0</link>
      <guid>https://dev.to/4ugusta/the-google-ads-api-has-no-compare-and-set-five-rules-for-software-that-edits-an-ad-account-48i0</guid>
      <description>&lt;p&gt;Someone agrees to a change to the campaign on Monday. This change was suggested four days ago. Then someone else changes the budget over the weekend. What does the approval write? The Google Ads API overwrites the contents of whatever is in the record. "Overwrite" means "replace the value in the record with the new value". It is not possible to say what you expect to be on the record, though. An overwrite cannot say "set it to 40, but only if it is still 25". What is missing is "but only if" which is called "compare and set" by programmers. The API is clever enough to refuse two attempts to write to the same record, happening at the same time. It gives a "concurrent modification" error message. This will not work against someone who did something on the Saturday. I wrote Admiral, which reads Google Ads accounts once a day and then suggests some fixes. Lack of compare and set means a very careful human approval of something that the human would not have seen. Five rules that Admiral runs on. They are not clever. They are the minimum required, because the simple, obvious design does not work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Old way
&lt;/h2&gt;

&lt;p&gt;The obvious design has 2 sections. Rules that apply themselves ("if a keyword spends with no result pause it") and an approve button that triggers a change stored when the suggestion is created. Both components fail the same way. They're based on a snapshot of the account that has aged.&lt;/p&gt;

&lt;h2&gt;
  
  
  One door
&lt;/h2&gt;

&lt;p&gt;All writes pass through one function. The one with Approve, that overnight automation and Undo all call. There is no other way to write to the account.&lt;/p&gt;

&lt;p&gt;It sounds neat, but this is the very rule that the others depend on. It is the rule where checks that are in one place cannot be skipped by the caller that forgot them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The list is in the code
&lt;/h2&gt;

&lt;p&gt;There is very little that automation may do without a person. What it may do is listed in the program code itself, and is not listed in a table of settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Illustrative. The only moves that may run without a tap.&lt;/span&gt;
&lt;span class="no"&gt;RUNS_ALONE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"add_negative_keywords"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;# block a search that never buys&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"set_keyword_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"PAUSED"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="c1"&gt;# pause a keyword&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;may_run_alone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;kind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"params"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;RUNS_ALONE&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;RUNS_ALONE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of this stuff in the list means "Stop spending money." "Don't show this ad on this search." Pausing a keyword means to stop spending. There's nothing on the list that can start spending money: no switching things on, no bids, no budgets. You can make a rule to act on its own, and that still doesn't change anything, because it can do nothing but the stuff on this list, since the check reads the action, not the value of the rule setting. Why code and not config? Somebody will open up a settings page at some point to widen it at 2am to fix a customer's problem. Things in the source code need a review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Daily cap
&lt;/h2&gt;

&lt;p&gt;The owner can control the number of changes that may be made alone in a day. The plan imposes a limit on it. The overnight pass tracks the number of changes made so far today and stops when the lower of the two limits is reached.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner_cap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plan_ceiling&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;applied_today&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# the rest wait for a person&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It has no write access to its own limits. That is all the design is: that thing that acts and that thing that decides how much it can act are not the same thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the approval
&lt;/h2&gt;

&lt;p&gt;It's the "only if it is still 25" part that the API doesn't support. This is hand-built so it has two parts: 1. On filing a suggestion, write the value it was built on: what budget it was built on, what status it was built on. 2. On approval, read the value live again before writing it. If it's been moved, reject it, don't write anything back, tell them in words they can act on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;live&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_live_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;live&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;proposal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueMoved&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"This was {proposal.expected} when it was suggested. It is {live} now."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;change&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, this needs three things before it works:&lt;/p&gt;

&lt;p&gt;Suggestions expire: Admiral suggestions expire after 7 days, and an expired suggestion never gets applied, regardless of what the database says for the suggestion's status. The status is updated by a job that is scheduled, so a job that has not yet run is not permission. Undo is a write. Its expected state is the value that the software wrote. If the account has moved since, undo fails for the same reason approve fails.&lt;/p&gt;

&lt;p&gt;Second, if the automation encounters a suggestion with a moved value or an expired suggestion, this is not an error. Nothing got written. The suggestion will wait for someone to do something or the next read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zero is not always zero
&lt;/h2&gt;

&lt;p&gt;A keyword that has clicks but no sales looks like a waste. On an account that has never recorded a sale or an enquiry, a zero may indicate that there's an issue with the tracking, not the keyword. It'd be stupid to pause on a broken tracking system.&lt;/p&gt;

&lt;p&gt;Findings can be flagged to require a human to look before they're passed in the overnight pass, whatever the mode. Campaigns that have been marked by the owner to be left alone are skipped, even for suggestions filed before they were marked.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a change leaves behind
&lt;/h2&gt;

&lt;p&gt;Every write is marked with who, why, before and after values. For clean changes, there is an undo. If a clean undo doesn't exist, then we make sure the change has a note saying that. We don't guarantee an undo for all changes, because some changes can't be cleanly undone.&lt;/p&gt;

&lt;p&gt;Changes that aren't made through the software (e.g. in the Google Ads interface, or by an auto-applied recommendation) are also shown in the history, marked as not ours.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you are starting
&lt;/h2&gt;

&lt;p&gt;Decide what your software will never do before you decide what it will do. Put that in code. Treat all approvals as approval for an account that no longer exists. You must verify the approval before you write.&lt;/p&gt;

&lt;p&gt;Admiral: &lt;a href="https://meetadmiral.com/start" rel="noopener noreferrer"&gt;https://meetadmiral.com/start&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googleads</category>
      <category>api</category>
      <category>automation</category>
      <category>python</category>
    </item>
  </channel>
</rss>
