question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Precondition Failed 412 Error when Updating a Report

See original GitHub issue

Starting last Saturday (April 28th) we get an exception when we try to update report dates using the DCM Reporting API. The error doesn’t happen all the time but it happens quite a lot on our process since it updates a lot of reports every day. It is really unclear why we started to get this error suddenly without changing anything in our process.

I hope you could help us understand how to solve the problem. Please find below the exception we get and the method which performs the update in C# code.

Please let me know if you need any further information in order to figure it out.

The exception:

Google.Apis.Requests.RequestError Precondition Failed [412] Errors [ Message[Precondition Failed] Location[If-Match - header] Reason[conditionNotMet] Domain[global] ] at Google.Apis.Requests.ClientServiceRequest1.<ParseResponse>d__34.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Google.Apis.Requests.ClientServiceRequest1.Execute() at ExtractDataFromDCM.DfaReporter.UpdateReportDates(Int64 profileId, Int64 reportId, DateTime startDate, DateTime endDate) in C:\Sources\ExtractDataFromDCM\3p\ExtractDataFromDCM\DfaReporter.cs:line 160

The method which updates the report dates (C# code):

public Report UpdateReportDates(long profileId, long reportId, DateTime startDate, DateTime endDate)
        {
            try
            {
                //Gets the report from DoubleClick.
                var report = GetReport(profileId);
 
                //Create the report if it doesn't exist.
                if (report == null)
                {
                    return CreateReport(profileId, startDate, endDate);
                }
 
                //Change dates format as DoubleClick expects it.
                var dateRange = new DateRange
                {
                    EndDate = endDate.ToString("yyyy-MM-dd"),
                    StartDate = startDate.ToString("yyyy-MM-dd")
                };
 
                //Updates the dates in the report object.
                report.Criteria.DateRange = dateRange;
 
                //Updates the report object in DoubleClick.
                return _service.Reports.Update(report, profileId, reportId).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to update report #{reportId} for profile #{profileId} in DoubleClick", ex);
            }
        }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:26

github_iconTop GitHub Comments

1reaction
chrisdunelmcommented, May 4, 2018

The error is stating that the etag header does not match on the update request. This probably means that the report has already been updated between where the code calls GetReport(), before _service.Reports.Update(...). Is it possible that the code is updating the same report multiple times concurrently? This would trigger this situation.

0reactions
jskeetcommented, May 29, 2020

@cfrederickson-kpbsd: Given that this is about a different API, I suspect it’s a different cause, and it would be best to open a new issue. Please include more details of what you mean by “For further information, the ETags are different.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

412 Precondition Failed - HTTP - MDN Web Docs - Mozilla
The HyperText Transfer Protocol (HTTP) 412 Precondition Failed client error response code indicates that access to the target resource has ...
Read more >
412 Precondition Failed - HTTP status code explained
HTTP response status code 412 Precondition Failed is a client error that is returned by the server to indicate that one or more...
Read more >
412 Precondition Failed - HTTP
The HyperText Transfer Protocol (HTTP) 412 Precondition Failed client error response code indicates that access to the target resource has been denied.
Read more >
412 Precondition Failed - HTTP Status Code Glossary
An HTTP 412 status code is used for HTTP requests are not HTTP method HEAD or HTTP method GET. When the 412 precondition...
Read more >
Precondition Failed error 412 when trying to post a ...
Hi, we are using below Microsoft Graph API to send a message to the team's chat. But we are getting below error message....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found